I have a formulated cell containing one string specifying only the worksheets where I want to modify certain cell under certain conditions:
Notes: Worksheets "Total", and "Test1" through "Test20" have the same format (I have more worksheets with different names and formats that I don't want to modify at all).
Let's say I want to modify the cell A5 in worksheets "Total", "Test2", "Test7" and "Test12"
A hidden formulated cell (let's say B50) has been formulated to get the following text string: "Array("Total", "Test2", "Test7", "Test12")". I am assigning this value to a variable expecting it to become part of the vba code where Sheets(SheetNamesList).Select can actually be Sheets(Array("Total", "Test2", "Test7", "Test12")).Select
I am getting a Suscript out of range Error and the line [Sheets(SheetNamesList).Select] is highlighted when debugging.
Below is my code. Thank you for your comments
Sub Active_to_Installed()
Dim SheetNamesList As String
SheetNamesList = Sheets("Names").Range("B50").Value
If Range("B50").Value = "A" Then
Range("B50").Activate
Sheets(SheetNamesList).Select
ActiveSheet.Activate
Range("A5").Select
ActiveCell.FormulaR1C1 = "I"
Else
Range("A5").Activate
Sheets(SheetNamesList).Select
ActiveSheet.Activate
Range("A5").Select
ActiveCell.FormulaR1C1 = "A"
End If
End sub
SheetNamesList
when the error occurs? Check this in the Locals window, or write?SheetNamesList
in the Immediate window. – Jean-François Corbett Oct 23 '13 at 18:33