Consolidate data from several sheets between two “bookends” into one sheet

stefk

New Member
Joined
Jul 25, 2019
Messages
4
I'm looking to tweak some code I already have that consolidates data from multiple sheets into a single, master sheet.
Currently the VBA selects all sheets that starts with the prefix "A-", copies select cells and pastes them into the consolidation sheet.
The change I would like to make is rather than select sheets starting with "A-", instead select all sheets between two sheets. For Simplicity, let's call these "StartSheet" and "EndSheet"
Illustratively it would look something like this:
< startsheet > < analysis1 > < analysis2 > < analysis3 > < endsheet >
Reason being, I, or someone else, can then just drop the analysis sheets between the bookends without risk of lookups and naming conventions.
I've tried a few ways to attempt to fuse my existing code with other examples I have found online but none seem to work. Help greatly appreciated!!
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">
Sub compile()

SelectSheets
"A-", ThisWorkbook

'Some other bits and pieces here
End Sub


Sub SelectSheets(sht As String, Optional wbk As Workbook)

Dim wks As Worksheet
Dim ArrWks() As String
Dim I As Long

If wbk Is Nothing Then Set wbk = ActiveWorkbook

ReDim ArrWks(0 To Worksheets.Count - 1)
For Each wks In Worksheets
If InStr(1, wks.Name, sht) > 0 Then
ArrWks
(I) = wks.Name
I
= I + 1
End If
Next wks
ReDim Preserve ArrWks(I - 1)
Sheets
(ArrWks).Select

Application
.ScreenUpdating = False

For Each ws In Sheets(ArrWks)
ws
.Range("A23:CU27,A35:CU54,A56:CU58,A62:CU71,A74:CU84").Copy
Worksheets
("consol").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)


Next ws


Application
.CutCopyMode = False
Application
.ScreenUpdating = True

End Sub</code>
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi & welcome to MrExcel.
How about
Code:
Sub stefk()
   Dim i As Long
   
   For i = Sheets("Start").Index + 1 To Sheets("End").Index - 1
      Sheets(i).Range("A23:CU27,A35:CU54,A56:CU58,A62:CU71,A74:CU84").Copy
      Worksheets("consol").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
   Next i
   Application.CutCopyMode = False
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
How about
Code:
Sub stefk()
   Dim i As Long
   
   For i = Sheets("Start").Index + 1 To Sheets("End").Index - 1
      Sheets(i).Range("A23:CU27,A35:CU54,A56:CU58,A62:CU71,A74:CU84").Copy
      Worksheets("consol").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
   Next i
   Application.CutCopyMode = False
End Sub

worked like a charm! thank you
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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