murugavelmsc
08-10-2011, 09:29 PM
Hi,
I have the "Runtime Error 9: Subscript out of Range" in the following code.
Sub SaveWithoutMacros()
Dim stemp As Variant
i = 1
For Each sht In Sheets
If i = 1 Then
a = sht.Name
If Sheets(a).Visible = True Then
stemp = stemp & """" & sht.Name & """"
End If
i = i + 1
Else
a = sht.Name
If Sheets(a).Visible = True Then
stemp = stemp & ", """ & sht.Name & """"
End If
End If
'msgbox sht.Name
Next sht
msgbox stemp
'Sheet1.Range("A1").Value = stemp
'Sheets(stemp).Select
Sheets(Array(stemp)).Select 'Error in this line
Sheets(Array(stemp)).Copy
End Sub
Please help me.
Regards
Murugavel S
I have the "Runtime Error 9: Subscript out of Range" in the following code.
Sub SaveWithoutMacros()
Dim stemp As Variant
i = 1
For Each sht In Sheets
If i = 1 Then
a = sht.Name
If Sheets(a).Visible = True Then
stemp = stemp & """" & sht.Name & """"
End If
i = i + 1
Else
a = sht.Name
If Sheets(a).Visible = True Then
stemp = stemp & ", """ & sht.Name & """"
End If
End If
'msgbox sht.Name
Next sht
msgbox stemp
'Sheet1.Range("A1").Value = stemp
'Sheets(stemp).Select
Sheets(Array(stemp)).Select 'Error in this line
Sheets(Array(stemp)).Copy
End Sub
Please help me.
Regards
Murugavel S