Solved

Copying data from one spreadsheet to another

Posted on 2015-01-07
8
57 Views
Last Modified: 2015-02-05
Hi,

I currently have 5 different spreadsheets with different data on it, is it possible to copy all the data from each of the spreadsheets to a master spreadsheet automatically.

I tried various VBA examples online but can't find one that can copy multiple rows over to the master spreadsheet.

Thanks
0
Comment
Question by:MattToner
  • 3
  • 3
8 Comments
 
LVL 12

Expert Comment

by:FarWest
ID: 40535832
if you want to copy certain  rows you can use Range
range("n1:n2")
where n1 is a start row number and n2
you can select and  copy the range and then select starting of destination and then paste

I hope this will help
0
 

Author Comment

by:MattToner
ID: 40535847
Hi, thanks for that, would you have a working example I could try?
0
 
LVL 12

Expert Comment

by:FarWest
ID: 40535887
this is a working example

Public Sub copyrows()
Sheet1.Activate
Sheet1.Range("1:4").Select
Selection.Copy
Sheet2.Activate
Sheet2.Range("1:1").Select
Sheet2.Paste
End Sub

Open in new window

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:MattToner
ID: 40537416
Hi thanks.

Is it possible so that it automatically grabs it from the 5 spreadsheets and put it into a different workbook?
0
 
LVL 12

Accepted Solution

by:
FarWest earned 500 total points
ID: 40538406
check this code

Public Sub copyrows()
	Dim wsh As Worksheet, wsr
	Dim startrow As Integer
	Dim LastRow As Integer
	startrow = 1 ' first row to copy to in destination
	Set wsr = Worksheets("AllSheets") ' this is the sheet name that will merge all others

	For Each wsh In ActiveWorkbook.Sheets
		If wsh.Name <> "AllSheets" Then
			wsh.Activate
			LastRow = wsh.UsedRange.SpecialCells(xlCellTypeLastCell).Row
			wsh.Range("1:" + LTrim(Str(LastRow))).Select ' or comment this and uncomment next line  if you need specific rows in sheet
			'wsh.Range("1:4").Select
			Selection.Copy
			wsr.Activate
			wsr.Range("A" + LTrim(Str(startrow)) + ":A" + LTrim(Str(startrow))).Select
			wsr.Paste
			startrow = startrow + LastRow ' + 1 or + 2 if you need spaces between sheets
		End If
	Next
End Sub

Open in new window

0
 

Author Comment

by:MattToner
ID: 40539730
Thank you, I'll have a look at it
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40590665
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question