Compiling multiple worksheets - Add additional columns with static data

stefk

New Member
Joined
Jul 25, 2019
Messages
4
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:
  • 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
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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