Hi Excel Ninjas,
As i am new to VBA and I have been stuck for hours now, I would really appreciate your help.
I am trying to copy paste the first two tabs of a file that can be located anywhere on someones machine. (This is why I am trying to use the application get open file and to assign it a dim = WB2op
It seems that the reference to the workbooks is not correct when i go from one to the other...
Please help!!!
Thanks in advance
Sub ImportFile()
Dim WB2op As String
Dim CurWB As Workbook
Set CurWB = ThisWorkbook
WB2op = Application.GetOpenFilename _
(Title:="Please choose File", _
FileFilter:="Excel Files *.xlsx* (*.xlsx*),")
If WB2op = "False" Then
MsgBox "No file selected.", vbExclamation
Exit Sub
'Workbooks("mybook").Sheets("mysheet").Range("A1:A10"
Else
Workbooks.Open Filename:=WB2op
Windows("CurWB").Activate
Sheets(5).Select
Range("A1:AA15000").ClearContents
Windows("WB2op").Activate
Sheets(1).Select
Range("A1:N15000").Copy
Windows("CurWB").Activate
Sheets(5).Range("A1").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=True, Transpose:=False
Application.CutCopyMode = False
Sheets(5).Range("A1").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Windows("CurWB").Activate
Sheets(4).Select
Range("A1:AA30000").ClearContents
Windows("WB2op").Activate
Sheets(2).Select
Range("A1:N15000").Copy
Windows("CurWB").Activate
Sheets(4).Range("A1").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=True, Transpose:=False
Application.CutCopyMode = False
Sheets(4).Range("A1").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End If
End Sub
As i am new to VBA and I have been stuck for hours now, I would really appreciate your help.
I am trying to copy paste the first two tabs of a file that can be located anywhere on someones machine. (This is why I am trying to use the application get open file and to assign it a dim = WB2op
It seems that the reference to the workbooks is not correct when i go from one to the other...
Please help!!!
Thanks in advance
Sub ImportFile()
Dim WB2op As String
Dim CurWB As Workbook
Set CurWB = ThisWorkbook
WB2op = Application.GetOpenFilename _
(Title:="Please choose File", _
FileFilter:="Excel Files *.xlsx* (*.xlsx*),")
If WB2op = "False" Then
MsgBox "No file selected.", vbExclamation
Exit Sub
'Workbooks("mybook").Sheets("mysheet").Range("A1:A10"
Else
Workbooks.Open Filename:=WB2op
Windows("CurWB").Activate
Sheets(5).Select
Range("A1:AA15000").ClearContents
Windows("WB2op").Activate
Sheets(1).Select
Range("A1:N15000").Copy
Windows("CurWB").Activate
Sheets(5).Range("A1").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=True, Transpose:=False
Application.CutCopyMode = False
Sheets(5).Range("A1").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Windows("CurWB").Activate
Sheets(4).Select
Range("A1:AA30000").ClearContents
Windows("WB2op").Activate
Sheets(2).Select
Range("A1:N15000").Copy
Windows("CurWB").Activate
Sheets(4).Range("A1").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=True, Transpose:=False
Application.CutCopyMode = False
Sheets(4).Range("A1").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End If
End Sub