Hi All,
I am new to VBA and this is my first post in this forum. I am currently stuck with an VBA error and can somebody help me on this plz.
Case Scenario : Copy paste sheets (cells.select) from one book (test.xlsx) to another (book1.xlsm) with sheet names declared with variables C1, C2, C3 & P1, P2, P3.. i.e., Copy paste C1 to P1 etc..
Below is the sample code, which I am trying to achieve. I am currently facing errors "Subscript out of range".
Sub Macro1()
'
' Macro1 Macro
'
'
Dim C, P As Worksheet
Workbooks.Open Filename:="C:\Users\girish.gs\Desktop\test.xlsx"
C1 = "abc" 'Sheetname in the workbook test.xlsx
C2 = "def" 'Sheetname in the workbook test.xlsx
C3 = "lmn" 'Sheetname in the workbook test.xlsx
P1 = "jkl" 'Sheetname in the workbook Book1.xlsm
P2 = "fgh" 'Sheetname in the workbook Book1.xlsm
P3 = "xyz" 'Sheetname in the workbook Book1.xlsm
For i = 1 To 3
C = "C" & i
P = "P" & i
Windows("test.xlsx").Activate
Worksheets(C).Select
Cells.Select
Application.CutCopyMode = False
Selection.Copy
Windows("Book1").Activate
Worksheets(P).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next i
End Sub
I am new to VBA and this is my first post in this forum. I am currently stuck with an VBA error and can somebody help me on this plz.
Case Scenario : Copy paste sheets (cells.select) from one book (test.xlsx) to another (book1.xlsm) with sheet names declared with variables C1, C2, C3 & P1, P2, P3.. i.e., Copy paste C1 to P1 etc..
Below is the sample code, which I am trying to achieve. I am currently facing errors "Subscript out of range".
Sub Macro1()
'
' Macro1 Macro
'
'
Dim C, P As Worksheet
Workbooks.Open Filename:="C:\Users\girish.gs\Desktop\test.xlsx"
C1 = "abc" 'Sheetname in the workbook test.xlsx
C2 = "def" 'Sheetname in the workbook test.xlsx
C3 = "lmn" 'Sheetname in the workbook test.xlsx
P1 = "jkl" 'Sheetname in the workbook Book1.xlsm
P2 = "fgh" 'Sheetname in the workbook Book1.xlsm
P3 = "xyz" 'Sheetname in the workbook Book1.xlsm
For i = 1 To 3
C = "C" & i
P = "P" & i
Windows("test.xlsx").Activate
Worksheets(C).Select
Cells.Select
Application.CutCopyMode = False
Selection.Copy
Windows("Book1").Activate
Worksheets(P).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next i
End Sub