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
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,449
Members
448,966
Latest member
DannyC96

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