Hi everyone. In a bit of a pickle again!
I have some vba code that compiles a fixed range of cells across multiple worksheets into a single consolidated sheet. So far so good.
What I would like to do now, is to add some additional columns to all the consolidated data with some of the attributes of the analysis that I am using. For example:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"]Sheet [/TD]
[TD="align: center"]Revenue [/TD]
[TD="align: center"]Costs [/TD]
[TD="align: center"]Data Run date[/TD]
[TD="align: center"]Username [/TD]
[TD="align: center"]File name [/TD]
[/TR]
[TR]
[TD]Sheet 1[/TD]
[TD]452.34[/TD]
[TD]234.65[/TD]
[TD]05/08/2019[/TD]
[TD]sk[/TD]
[TD]consol file[/TD]
[/TR]
[TR]
[TD]Sheet 2[/TD]
[TD]7984.34[/TD]
[TD]2234.34[/TD]
[TD]05/08/2019[/TD]
[TD]sk[/TD]
[TD]consol file[/TD]
[/TR]
[TR]
[TD]Sheet ...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
</tbody>[/TABLE]
So my existing macro covers the first two columns in Blue, which are dynamic and based on the calculations in the sheets between the bookends. But it is the columns in red that I am stuck on, which will be static based on that particularly run of the analysis. These columns are populated with the same info for all line items where there are values.
A few other things:
In advance, your help is greatly appreciated!
I have some vba code that compiles a fixed range of cells across multiple worksheets into a single consolidated sheet. So far so good.
What I would like to do now, is to add some additional columns to all the consolidated data with some of the attributes of the analysis that I am using. For example:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"]Sheet [/TD]
[TD="align: center"]Revenue [/TD]
[TD="align: center"]Costs [/TD]
[TD="align: center"]Data Run date[/TD]
[TD="align: center"]Username [/TD]
[TD="align: center"]File name [/TD]
[/TR]
[TR]
[TD]Sheet 1[/TD]
[TD]452.34[/TD]
[TD]234.65[/TD]
[TD]05/08/2019[/TD]
[TD]sk[/TD]
[TD]consol file[/TD]
[/TR]
[TR]
[TD]Sheet 2[/TD]
[TD]7984.34[/TD]
[TD]2234.34[/TD]
[TD]05/08/2019[/TD]
[TD]sk[/TD]
[TD]consol file[/TD]
[/TR]
[TR]
[TD]Sheet ...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
</tbody>[/TABLE]
So my existing macro covers the first two columns in Blue, which are dynamic and based on the calculations in the sheets between the bookends. But it is the columns in red that I am stuck on, which will be static based on that particularly run of the analysis. These columns are populated with the same info for all line items where there are values.
A few other things:
- There could be a variable number of sheets for consolidation - they are within two bookends called "start" and "end"
- The red columns will always come from the same location - for now lets call this the range A1:A5 in a sheet called "static"
- I would like the copy paste attributes to follow that of the existing code, i.e. look for the next blank row and populate
- I have a paste special:transpose function. So in my code below, column CU corresponds to column BA after transposition
In advance, your help is greatly appreciated!
Code:
Sub compiler2()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Dim i As Long
Application.Calculation = xlCalculationManual
For i = Sheets("start").Index + 1 To Sheets("end").Index - 1
Sheets(i).Range("J3:CU4,J23:CU29,J35:CU54,J56:CU58,J62:CU71,J74:CU84").Copy
Worksheets("consol").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues, Transpose:=True
Next i
Application.CutCopyMode = False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub