Solved

Copying data from one spreadsheet to another

Posted on 2015-01-07
8
55 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 45

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

757 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

19 Experts available now in Live!

Get 1:1 Help Now