Trying to indirectly reference ranges for arrays in a control sheet

galenthias

New Member
Joined
Feb 22, 2021
Messages
1
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi,

I have a workbook which has multiple sheets for our product ranges. Each sheet is laid out the same with the same charts and tables.

I've created code that will take a specified range in the vba of each sheet and copy the contents as an image into a presentation which 1 range per slide. It's working well but I will need to do the same for many more products.

Instead of manually writing all the arrays into the VBA code is there a way of having my Control sheet with a list of sheets and their ranges next to them to be used in the arrays as some of the ranges can change sheet to sheet?

Current array selection:
RngArray = Array(Worksheets("PROD1").Range("C1:Y43"), Worksheets("PROD2").Range("C1:Y44"))

The CONTROL sheet would be like this:

SheetRange1
PROD1C1:Y43
PROD2C1:Y44

I've come back to VBA after 12 years away from it and I'm a bit rusty! :)

Thank you!

Pen
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

mart37

Well-known Member
Joined
Aug 4, 2017
Messages
1,061
Office Version
  1. 2016
Platform
  1. Windows
VBA Code:
Sub MakeImages()
    Dim shControl As Worksheet
    Dim rngArray As Range
    Dim lLastrow As Long
    Dim shName As String
    Dim sRange As String
    Set shControl = Worksheets("Control") 'name of the control sheet
    lLastrow = shControl.Range("A" & Rows.Count).End(xlUp).Row
    For x = 2 To lLastrow
        shName = shControl.Range("A" & x)
        sRange = shControl.Range("B" & x)
        Set rngArray = Worksheets(shName ).Range(sRange)
        'here your code
    Next
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,127,596
Messages
5,625,721
Members
416,130
Latest member
galgozzi

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
Top