Sub CopymyWs()
Dim myWsLastColLet As String
Dim myWb As Workbook, masterWb As Workbook
Dim myWs As Worksheet, masterWs As Worksheet
Dim myWsLastRow As Long, masterWsLastRow As Long, myWsLastCol As Long
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
Set myWb = ActiveWorkbook 'set my file as myWb
Set myWs = myWb.ActiveSheet 'set current active worksheet in myWb as myWs
myWsLastRow = myWs.Range("A" & Rows.Count).End(xlUp).Row 'ID the last used Row on myWs
myWsLastCol = myWs.Cells(1, Columns.Count).End(xlToLeft).Column 'ID the last used column on myWs
If myWsLastCol > 26 Then
myWsLastColLet = Chr(Int((myWsLastCol - 1) / 26) + 64) & Chr(((myWsLastCol - 1) Mod 26) + 65) 'change column number to letter if column higher then 26
Else
myWsLastColLet = Chr(myWsLastCol + 64) 'change column number to letter if column 1 - 26
End If
masterFile = Application.GetOpenFilename("Excel File (*.xls*),") 'Identify the file name and type of file to open
If masterFile = False Then Exit Sub 'If no file is selected end the code
Workbooks.Open masterFile 'Open master file
Set masterWb = ActiveWorkbook 'Set the master file as masterWb
Set masterWs = masterWb.ActiveSheet 'Set the sheet the master file opens to as the masterWs (this is where the data will be saved)
masterWsLastRow = masterWs.Range("A" & Rows.Count).End(xlUp).Row + 1 'ID the last used row of the master file, add 1 to it
myWs.Range("A2:" & myWsLastColLet & myWsLastRow).Copy 'Copy data from my file
masterWs.Range("A" & masterWsLastRow).PasteSpecial 'Paste data to master file
masterWb.Close SaveChanges:=True 'Save and Close the master file
Set masterWs = Nothing
Set masterWb = Nothing
Set myWs = Nothing
Set myWb = Nothing
With Application
.CutCopyMode = False
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub