VBA - Referencing a jagged array index in For loop

CRHAAG

New Member
Joined
Jul 3, 2014
Messages
46
I have an array of arrays and am trying to cycle through it and run macros based on the index in the array. My code is as follows




VBA Code:
Dim reportList As Variant  
'sheet, button, report
    reportList = Array( _
        Array("scpSumBox", "RPscopeOfWorkSummary", "Scope of Work Summary"), _
        Array("prpSumBox", "RPprpFixtures", "Proposed Fixture Summary"), _
        Array("exstSumBox", "RPexistingFixtures", "Existing Fixture Summary") _
        )
    
    'Cycle through list and create reports
    For i = 0 To UBound(reportList)
        If Sheets("REPORT").reportList(i)(0).Value = True Then
            Call reportList(i)(1)
        End If
        Next i

The debugger is highlighting Call reportList(i)(1) between the i and the 1 and saying:
Compile Error: Expected end of statement

The items in the array are as follows
Index 0 - name of a radio button
index 1 - name of a macro that creates a report
index 2 - name of the report that it will eventually create

Right now I am trying to get the For Loop to run the macro at the index in reportList

Any insight would be appreciated
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
If radio buttons are Active X controls, then it could be.
Macros "prpSumBox"... must be in a module.

VBA Code:
Sub test()
  Dim i As Long
  Dim reportList As Variant
  'sheet, button, report
  reportList = Array( _
    Array("scpSumBox", "RPscopeOfWorkSummary", "Scope of Work Summary"), _
    Array("prpSumBox", "RPprpFixtures", "Proposed Fixture Summary"), _
    Array("exstSumBox", "RPexistingFixtures", "Existing Fixture Summary"))
  
  'Cycle through list and create reports
  For i = 0 To UBound(reportList)
    If Sheets("REPORT").OLEObjects(reportList(i)(0)).Object.Value = True Then
      Run reportList(i)(1)
    End If
  Next i
End Sub
 
Upvote 0
If radio buttons are Active X controls, then it could be.
Macros "prpSumBox"... must be in a module.

VBA Code:
Sub test()
  Dim i As Long
  Dim reportList As Variant
  'sheet, button, report
  reportList = Array( _
    Array("scpSumBox", "RPscopeOfWorkSummary", "Scope of Work Summary"), _
    Array("prpSumBox", "RPprpFixtures", "Proposed Fixture Summary"), _
    Array("exstSumBox", "RPexistingFixtures", "Existing Fixture Summary"))
 
  'Cycle through list and create reports
  For i = 0 To UBound(reportList)
    If Sheets("REPORT").OLEObjects(reportList(i)(0)).Object.Value = True Then
      Run reportList(i)(1)
    End If
  Next i
End Sub
That did the trick!!! Thanks so much
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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