Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Copying data from one spreadsheet to another

Posted on 2015-01-07
8
Medium Priority
?
63 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 2000 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 49

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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…

916 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