In one workbook, there are some hundred worksheets.
I am trying to merge a certain range (A2:D6) from certain worksheets (whose name end in "_A" or "_B") into one worksheet ("combined").
The data structure is the same across the target sheets:
the target sheet names all end in "_A" or "_B" : for example
Code1_A
Code1_B
Code2_A
Code2_B
Code3_A
Code3_B
.
.
.
I want to combine them like this PASTING as VALUE and keeping the FORMAT:
At the moment, I have the following code:
Sub Merge ()
Dim Sheet As Worksheet
For Each Sheet In ActiveWorkbook.Sheets
If Sheet.Name Like "*" & strSearch & "_A" Or _
Sheet.Name Like "*" & strSearch & "_B" Then
Sheets(Sheet.Name).Range("A2:D6").Copy
End If
Next
With Worksheets("Combined").Range("A2")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
End With
End Sub
*Problem: my code looks for sheets ending in "_A" and "_B", but either overwrites them or gets the first instance of the match. How to fix it to get ALL sheets ending in "_A" or "_B" and to loop until all the ranges from all the target sheets are combined one under the other?
Or is there any other way to achieve this faster?