Merging selected worksheets from workbooks (Solved)

Samnuni

Board Regular
Joined
Sep 27, 2005
Messages
206
Hi, I have four excel files with the same number of worksheets (four) in the same order and with the same names. I only want sheet2 and sheet3 to be merged into another workbook that has the same format as the others. I got a macro from this board copying all the worksheets into one workbook under respected worksheets.

The code I included is the cycling of the worksheets and what I think needs modification is the line:
Code:
For Each w In ActiveWorkbook.Worksheets
so that it only deals with sheet2 and sheet3 instead of every worksheet in the workbooks. The only problem I have I have no idea on how to do that.

I tried using an If statement with GoTo to skip the copying process when the sheet name is what I want to skip, but I couldn't get it to work... Thanks in advance.

Code:
On Error Resume Next 
For x = 1 To 4

For Each w In ActiveWorkbook.Worksheets 
v = w.Name 

If Application.CountA(w.Columns(1)) = 1 Then 
Alr = 2 
Else 
Alr = w.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End If 
If Application.CountA(ThisWorkbook.Worksheets(v).Cells) <> 0 Then 
Tlr = ThisWorkbook.Worksheets(v).Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1 
Else 
Tlr = 1 
End If 

w.Rows("2:" & Alr).Copy ThisWorkbook.Worksheets(v).Cells(Tlr, 1) 

Next w 
ActiveWorkbook.Close False 
Next x
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
This is, hopefully, a quick fix.
Replace the single line of code you have indicated with this two :-
Code:
    For s = 2 To 3
        Set w = ActiveWorkbook.Worksheets(s)
 
Upvote 0

Forum statistics

Threads
1,207,095
Messages
6,076,552
Members
446,213
Latest member
bettigb

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