Forum Discussion
EhrenJ
May 26, 2022Copper Contributor
Need help on VBA code
Hi guys,
Scenario:
Let's say I have 2 workbooks with their own different named sheets,
I created 2 arrays corresponding to their workbook sheets that I manually populate
Now the idea is, I want to make sure the ActiveWorkbook I have open falls into the criteria or matches with the sheets from one of the arrays before proceeding to the code execution.
FULL CODE BODY (For better understanding)
Sub Program()
Dim ws As worksheet
Dim wb As workbook
Dim Name1 As Variant
Dim Name2 As Variant
Set wb = ActiveWorkbook
Name1 = Array ("Sheet1", "Sheet2", "Sheet3")
Name2 = Array ("Sheet4", "Sheet5", "Sheet6")
For Each ws In wb.Sheets(Name1 Or Name2)
wsheet.Activate
Call anotherProgram
Next wsheet
End Sub
I am quite new to VBA coding hence I am not too familiar, perhaps my problem already has a solution, however, I just am not able to find the solution.
I was thinking of using If statements, however, it just wouldn't work.
TLDR:
1. Open a workbook with a set of sheets (with names)
2. Run a macro on that workbook based on the name of the sheets that are stored in an array within the code itself
- DevendraJainIron ContributorHello I can Solve the issue but I need a further explanation on Google Meet to actually understand the problem and will solve the issue at the same time on call itself