Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default consolidate data from worksheets

I have a workbook with one starting sheet named "master data".

After this sheet, there is a variable amount of sheets containing
data.

I would like to run the following macro to capture the data i need
from each sheet and paste to the master data sheet starting at row 10.
each paste should be subsequent to the previous paste.


Rows("10:10").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default consolidate data from worksheets

Hi J.W. Aldridge

Start here
http://www.rondebruin.nl/copy2.htm

See this example
Copy from row 2 till the last row with data


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"J.W. Aldridge" wrote in message
...
I have a workbook with one starting sheet named "master data".

After this sheet, there is a variable amount of sheets containing
data.

I would like to run the following macro to capture the data i need
from each sheet and paste to the master data sheet starting at row 10.
each paste should be subsequent to the previous paste.


Rows("10:10").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default consolidate data from worksheets


Ok. But how do i change the range portion

Set CopyRng = sh.Range("A1:G1")


to what I am needing (below)

Rows("10:10").Select
Range(Selection, Selection.End(xlDown)).Select

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default consolidate data from worksheets

'Fill in the start row
StartRow = 2

Change this to 10
Copy the macro and function below in a normal module of your workbook

Sub CopyDataWithoutHeaders()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
Dim shLast As Long
Dim CopyRng As Range
Dim StartRow As Long

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'Delete the sheet "RDBMergeSheet" if it exist
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("RDBMergeSheet").Delete
On Error GoTo 0
Application.DisplayAlerts = True

'Add a worksheet with the name "RDBMergeSheet"
Set DestSh = ActiveWorkbook.Worksheets.Add
DestSh.Name = "RDBMergeSheet"

'Fill in the start row
StartRow = 10
'loop through all worksheets and copy the data to the DestSh
For Each sh In ActiveWorkbook.Worksheets
If sh.Name < DestSh.Name Then

'Find the last row with data on the DestSh and sh
Last = LastRow(DestSh)
shLast = LastRow(sh)

'If sh is not empty and if the last row = StartRow copy the CopyRng
If shLast 0 And shLast = StartRow Then

'Set the range that you want to copy
Set CopyRng = sh.Range(sh.Rows(StartRow), sh.Rows(shLast))

'Test if there enough rows in the DestSh to copy all the data
If Last + CopyRng.Rows.Count DestSh.Rows.Count Then
MsgBox "There are not enough rows in the Destsh"
GoTo ExitTheSub
End If

'This example copies values/formats, if you only want to copy the
'values or want to copy everything look below example 1 on this page
CopyRng.Copy
With DestSh.Cells(Last + 1, "A")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With

End If

End If
Next

ExitTheSub:

Application.Goto DestSh.Cells(1)

'AutoFit the column width in the DestSh sheet
DestSh.Columns.AutoFit

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"J.W. Aldridge" wrote in message
...

Ok. But how do i change the range portion

Set CopyRng = sh.Range("A1:G1")


to what I am needing (below)

Rows("10:10").Select
Range(Selection, Selection.End(xlDown)).Select


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Consolidate data from multiple worksheets into one bartonHR Excel Discussion (Misc queries) 2 October 26th 07 05:04 PM
I need to consolidate data from 3 different worksheets? CG Excel Worksheet Functions 1 December 12th 05 01:04 AM
'Consolidate' data from multiple worksheets spliknik Excel Discussion (Misc queries) 4 November 3rd 05 01:32 PM
How to consolidate data from multiple worksheets. SAR Excel Worksheet Functions 0 August 28th 05 12:56 PM
Consolidate data from several worksheets via pivottable mthatt Excel Worksheet Functions 0 March 23rd 05 05:35 PM


All times are GMT +1. The time now is 01:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"