Unable to combine multiple (autofltered) sheets into a single worksheet

ezphua89

New Member
Joined
Feb 3, 2015
Messages
2
Hi,

I am not a vba expert and have been looking for vba codes online to help with merging multiple sheets into a single sheet.

Basically, I have multiple sheets that I have already filtered out for blanks in Column B. I would like to transfer that data of each spreadsheet (Column A-G, from rows 8 to last row) into a master sheet called "Combined". After pasting the data on to the master sheet, I would like the rows copied to be labelled with the sheet name they came from to be in Column I.

So far, the code that I am using does not go through each sheet and is unable to select the filtered data from each spreadsheet.

Code used below:


Sub CopyData()
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
' Set destination worksheet.
Set DestSh = Sheets("Combined")
DestSh.Name = "Combined"
' Fill in the start row.
StartRow = 5
' Loop through all worksheets and copy the data to the
' summary worksheet.
' Except for Info sheet and Summary II.

For Each Sh In ActiveWorkbook.Worksheets
If IsError(Application.Match(Sh.Name, _
Array(DestSh.Name, "Info Sheet", "Summary II"), 0)) Then

Sh.Select
LastRow = Range("B2000").End(xlUp).Row
Last = Range("B2000").End(xlUp).Row
Set CopyRng = Range("A8", Cells(LastRow, "H"))
CopyRng.Copy
With DestSh.Cells(Last + 1, "A")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With

' This statement will copy the sheet
' name in the I column.
DestSh.Cells(Last + 1, "I").Resize(CopyRng.Rows.Count).Value = Sh.Name
Else
End If
Next Sh
ExitTheSub:
Application.Goto DestSh.Cells(1)

DestSh.Columns.AutoFit
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub


Would appreciate any help given! Thank you much!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I think this:

Rich (BB code):
Last = Range("B2000").End(xlUp).Row

should be:

Rich (BB code):
Last = DestSh.Range("B2000").End(xlUp).Row
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top