RockandGrohl
Well-known Member
- Joined
- Aug 1, 2018
- Messages
- 788
- Office Version
- 2010
- Platform
- Windows
Hi guys, I have a report that has about 14 tabs in it. By repeating the template code from one tab to another I've gone over the 64kb limit (seriously, wtf VBA..) anyway
I have some set up that's done in the reporting module, and then it switched to each of the tabs, built them and moved on to the next tab. It's clear that I need the tab-building to be done in separate modules, but the problem is I don't want to declare the tab and workbook names in every module.
If I set up my tabs like this:
And other workbooks are opened like this:
Then how do I keep that consistent across procedures?
Currently, my report building is set up something like this:
In that little block, I might have to reference something like "bsam" or "af1" or "bd" which can be on the original workbook or a different workbook entirely..
So how do I do that? Thanks.
Worryingly, I have a lot of variables:
I have some set up that's done in the reporting module, and then it switched to each of the tabs, built them and moved on to the next tab. It's clear that I need the tab-building to be done in separate modules, but the problem is I don't want to declare the tab and workbook names in every module.
If I set up my tabs like this:
VBA Code:
Private Sub RunReport_Click()
Dim t3, bd As Worksheet
Dim Lastrow, LastrowBD, Lastcol As Long
Dim temp As Worksheet
Dim wbyr As String
Set t3 = Worksheets("T3 Data")
Set bd = Worksheets("Booking Database")
Set comm = Worksheets("Comm Matrix")
Set weksum = Worksheets("Weekly")
Set monsum = Worksheets("Monthly")
Set consum = Worksheets("Contract")
wbyr = 2021
tdate = Int(CDbl(DateValue(Date)))
And other workbooks are opened like this:
VBA Code:
Dim bsam, am, af1, af2 As Workbook
Dim al, pd As Worksheet
For Each wbk In Workbooks
If wbk.Name = "Budget Sales Allocation Master.xlsm" Then
wbk.Activate
If wbk.ReadOnly = False Then
wbk.Close True
Else
wbk.Close False
End If
End If
Next
Application.ScreenUpdating = False
Set bsam = Workbooks.Open("\\chw-dc03\company\Sales\Reporting\Budget\Budget Sales Allocation Master.xlsm", False, True)
Application.ScreenUpdating = True
Then how do I keep that consistent across procedures?
Currently, my report building is set up something like this:
VBA Code:
weksum.activate
'delete existing results here
' build new lines here
' insert formulas here
' format everything
' then do the next one
In that little block, I might have to reference something like "bsam" or "af1" or "bd" which can be on the original workbook or a different workbook entirely..
So how do I do that? Thanks.
Worryingly, I have a lot of variables:
VBA Code:
LastrowBD, Lastrowtemp, Lastcol, wbyr, tdate, t3, bd, af1, af2, bsam, am, comm, weksum, monsum, consum, refsum, feasum, namsum, tcatsum, catsum, depsum, dursum, ltsum
Last edited: