Solved

Copying data from one spreadsheet to another

Posted on 2015-01-07
8
56 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now