I have got a code for opening a file and copying data into another sheet.I have two files that I need to open and copy data from their only sheets into a workbook with two destination sheets. In short, two workbooks (each with a sheet) copied into one workbook(2 different sheets).
Currently, my macro pops up a open dialog box,i select a specific file(Trading files monthly) from a folder labelled trading accounts and open and copy and paste is done. Then another open dialog box pops up and another file is chosen (Retail monthly files) from a folder (retail reports).
I feel this is to cumbersome and I want to introduce an If
ElseIf statement into this .
A newbie and not sure how??any ideas.
Code is as ffs:
Sub mnuFileOpen_Click()
Dim FullFileName As String
Dim RetailPath As String
Dim wbThis As Workbook, wbTrad As Workbook, wbRet As Workbook
Set wbThis = ActiveWorkbook
FullFileName = Application.GetOpenFilename("Excel Files (*.xls),*.xls", False)
Application.StatusBar = "Opening " & FullFileName
Set wbTrad = Workbooks.Open(FullFileName)
wbTrad.Sheets(1).Range("A:H").Copy
wbThis.Sheets("FMA Data").Range("A1").PasteSpecial xlValues
Application.CutCopyMode = False
Application.StatusBar = "Closing " & FullFileName
wbTrad.Close
Application.StatusBar = False
RetailPath = Application.GetOpenFilename("Excel Files (*.xls),*.xls", False)
Application.StatusBar = "Opening " & RetailPath
Set wbRet = Workbooks.Open(RetailPath)
wbRet.Sheets(1).Range("A:H").Copy
wbThis.Sheets("Retail FMA").Range("A1").PasteSpecial xlValues
wbThis.Activate
ActiveWorkbook.Sheets("Retail FMA").Range("A1:H1").Select
Selection.Delete Shift:=xlUp
Application.CutCopyMode = False
Application.StatusBar = "Closing " & RetailPath
wbRet.Close
Application.StatusBar = False
End Sub
Currently, my macro pops up a open dialog box,i select a specific file(Trading files monthly) from a folder labelled trading accounts and open and copy and paste is done. Then another open dialog box pops up and another file is chosen (Retail monthly files) from a folder (retail reports).
I feel this is to cumbersome and I want to introduce an If
ElseIf statement into this .
A newbie and not sure how??any ideas.
Code is as ffs:
Sub mnuFileOpen_Click()
Dim FullFileName As String
Dim RetailPath As String
Dim wbThis As Workbook, wbTrad As Workbook, wbRet As Workbook
Set wbThis = ActiveWorkbook
FullFileName = Application.GetOpenFilename("Excel Files (*.xls),*.xls", False)
Application.StatusBar = "Opening " & FullFileName
Set wbTrad = Workbooks.Open(FullFileName)
wbTrad.Sheets(1).Range("A:H").Copy
wbThis.Sheets("FMA Data").Range("A1").PasteSpecial xlValues
Application.CutCopyMode = False
Application.StatusBar = "Closing " & FullFileName
wbTrad.Close
Application.StatusBar = False
RetailPath = Application.GetOpenFilename("Excel Files (*.xls),*.xls", False)
Application.StatusBar = "Opening " & RetailPath
Set wbRet = Workbooks.Open(RetailPath)
wbRet.Sheets(1).Range("A:H").Copy
wbThis.Sheets("Retail FMA").Range("A1").PasteSpecial xlValues
wbThis.Activate
ActiveWorkbook.Sheets("Retail FMA").Range("A1:H1").Select
Selection.Delete Shift:=xlUp
Application.CutCopyMode = False
Application.StatusBar = "Closing " & RetailPath
wbRet.Close
Application.StatusBar = False
End Sub