J
jfcby
Hello,
The following macro code gives the error: "Subscript out of range" on
this line: "wsA.Copy after:=wbB.Sheets(wbB.Sheets.Count)".
I'm trying to copy certain worksheets form one workbook to another
workbook.
Why am I getting this error and how can the following macro be
modified to copy the worksheets?
Sub CopyWorkSheets_()
Dim wbA As Workbook
Dim wbB As Workbook
Dim wsA As Worksheet
Set wbA = Workbooks("Equip_List_FF.xls")
Set wbB = Workbooks("FF_Zone5_Bldgs.xls")
For Each wsA In wbA.Worksheets
For Each cell In wbB.Worksheets("Index").Range("E4:E27")
If wsA.Visible = xlSheetHidden Then GoTo nws
'MsgBox "Worksheet Name = " & wsA.Name & " " & "Value = " &
Right(wsA.Range("C2").Value, 4) _
& " " & "cell = " & cell
If cell.Text = Right(wsA.Range("C2").Text, 4) Then
wsA.Copy after:=wbB.Sheets(wbB.Sheets.Count)
GoTo nws
End If
Next cell
nws:
Next wsA
End Sub
Than you for your help,
jfcby
The following macro code gives the error: "Subscript out of range" on
this line: "wsA.Copy after:=wbB.Sheets(wbB.Sheets.Count)".
I'm trying to copy certain worksheets form one workbook to another
workbook.
Why am I getting this error and how can the following macro be
modified to copy the worksheets?
Sub CopyWorkSheets_()
Dim wbA As Workbook
Dim wbB As Workbook
Dim wsA As Worksheet
Set wbA = Workbooks("Equip_List_FF.xls")
Set wbB = Workbooks("FF_Zone5_Bldgs.xls")
For Each wsA In wbA.Worksheets
For Each cell In wbB.Worksheets("Index").Range("E4:E27")
If wsA.Visible = xlSheetHidden Then GoTo nws
'MsgBox "Worksheet Name = " & wsA.Name & " " & "Value = " &
Right(wsA.Range("C2").Value, 4) _
& " " & "cell = " & cell
If cell.Text = Right(wsA.Range("C2").Text, 4) Then
wsA.Copy after:=wbB.Sheets(wbB.Sheets.Count)
GoTo nws
End If
Next cell
nws:
Next wsA
End Sub
Than you for your help,
jfcby