Define worksheets throught a loop using arrays

Mory19

New Member
Joined
Nov 28, 2022
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hi, I have two arrays based on existing sheets declare in the "sheetsNameGroup" variant and I want to define them in the loop and then activate the sheets outside the loop using (for example) cveSH.Activate, but when I tried it resulted in a 424 "object required" error ", which means I can only call sheets using "sheetsDefGroup(number)". I don't know if it is possible to do it and the closest thing but with the error I mention is the code below
VBA Code:
Sub Test()
Dim cveSH, cweSH, agentsSH, databaseSH As Worksheet 'How I would like to declare my Sheets.
Dim sheetsNameGroup, sheetsDefGroup as Variant 'Existing sheets in my workbook.
Dim counter as Integer
sheetsNameGroup = Array("cve", "cwe", "agents", "database")
sheetsDefGroup = Array("cveSH", "cweSH", "agentsSH", "databaseSH")
For counter = LBound(sheetsNameGroup) To UBound(sheetsNameGroup)
    Set sheetsDefGroup(counter) = Worksheets(sheetsNameGroup(counter))
Next counter
End sub
I know I can do a conditional statement if I wanted to Activate the "cve" Sheet through the existing array, but I would like to know if what I tried to do is possible, PD. I'm rlly sorry if my english sintax is not the better at the momment to explain the problem and if i've missed something important
 

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.
Your only declaring "databaseSH" as a worksheet. You need to...
Code:
Dim cveSH As Worksheet, cweSH As Worksheet, agentSHAs Worksheet , databaseSH As Worksheet 
Dim sheetsNameGroup as Variant, sheetsDefGroup as Variant
Not real sure what you're trying to accomplish? You're changing the contents of the sheetsDefGroup which already has the contents loaded? Also, no need to use "Set" to change array contents. Dave
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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