This is what I was going to post earlier:
I have 2 workbooks open, both with multiple identically named sheets. I would like to run a macro in wb1 (Active) to copy the selected range from each worksheet and paste to the corresponding worksheet in wb2 to the next blank column, row 6.
This is what i came up with (using a function for obtaining the column letter)
Code: Select all
Sub Append()
Dim wb1 As Workbook, wb2 As Workbook
Dim wsName As String
Dim ws As Worksheet
Dim strCol As String
Set wb1 = ActiveWorkbook
Set wb2 = Excel.Workbooks("xyz.xls") 'Also open
Application.ScreenUpdating = False
If ActiveSheet.Index = Sheets.Count Then
MsgBox "Process complete.", vbInformation, "Macro"
Else
Selection.Copy
wsName = ActiveSheet.Name
wb2.Activate
wb2.Sheets(wsName).Select
strCol = LastCol(6, "IV", wb2.Sheets(wsName), 1)
Range(strCol & "6").Select
ActiveSheet.Paste
wb1.Activate
ActiveSheet.Next.Select
Call Append
End If
Application.ScreenUpdating = True
End Sub
Also, if there is no corresponding ws in wb2, I would like to create one by copying the last ws in wb2 and renaming it, then paste.