CatDaddy
10-06-2011, 12:26 PM
im getting a 1004 error "1004 excel cannot insert the sheets into the destination workbook, because it contains fewer rows and columns than the source workbook" when i tried to make vba cycle through open workbooks and append a the worksheet from my macro book that shares the same name:
Sub addColumns()
Dim i As Integer
Dim wb As Workbook
Dim wbName(1 To 5) As String
Dim cV As Integer
i = 1
For Each wb In Application.Workbooks
If wb.Name <> ThisWorkbook.Name Then
wbName(i) = Left(wb.Name, InStrRev(wb.Name, ".") - 1)
i = i + 1
End If
Next wb
For i = 1 To 5
Workbooks(wbName(i) & ".xlsx").Activate
Application.CutCopyMode = False
ThisWorkbook.Sheets(wbName(i)).Copy After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
Next i
End Sub
ex: there is a workbook named NEWYORK.xlsx and i need the sheet in ThisWorkbook named "NEWYORK" to make a copy after all of the sheets in NEWYORK.xlsx
Sub addColumns()
Dim i As Integer
Dim wb As Workbook
Dim wbName(1 To 5) As String
Dim cV As Integer
i = 1
For Each wb In Application.Workbooks
If wb.Name <> ThisWorkbook.Name Then
wbName(i) = Left(wb.Name, InStrRev(wb.Name, ".") - 1)
i = i + 1
End If
Next wb
For i = 1 To 5
Workbooks(wbName(i) & ".xlsx").Activate
Application.CutCopyMode = False
ThisWorkbook.Sheets(wbName(i)).Copy After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
Next i
End Sub
ex: there is a workbook named NEWYORK.xlsx and i need the sheet in ThisWorkbook named "NEWYORK" to make a copy after all of the sheets in NEWYORK.xlsx