I have this code that:
- Clears my worksheet from row 12 and onward in Workbook A
- Opens a new file Workbook B
- Copys the sheet to my Workbook A. and Close Workbook B
- Renames sheet in Workbook A
- Transfers data from New Sheet to another Tab.
This seems to take me 10 minutes+, it is roughly 35k Rows.
Is there a faster way of doing this?
Thanks.
Sub Mainsub()
Worksheets("Main Data").Rows("12:" & Rows.Count).ClearContents
'Copy data from the CM File to Template
Application.ScreenUpdating = False
'Open CM file
Set MainDataCM = Workbooks.Open(Sheets("Input").Range("B16") & Sheets("Input").Range("B19"))
'Copy main data tab to EPM file workbook
MainDataCM.Sheets("Main Data").Copy After:=ThisWorkbook.Sheets(1)
'Close CM Comm file
MainDataCM.Close SaveChanges:=False
Application.ScreenUpdating = True
Sheets("Main Data (2)").Name = "CM_MainData"
Worksheets("CM_MainData").Visible = False
'Read the CM_MainData tab and copy the required columns in the MainData tab
Dim k As Long
k = Sheets("CM_MainData").Range("A1", Sheets("CM_MainData").Range("A1").End(xlDown)).Rows.Count
Debug.Print (k)
i = 12
j = 2
While j <= k
Sheets("Main Data").Range("A" & i) = Sheets("CM_MainData").Range("A" & j)
Sheets("Main Data").Range("B" & i) = Sheets("CM_MainData").Range("B" & j)
Sheets("Main Data").Range("C" & i) = Sheets("CM_MainData").Range("C" & j)
Sheets("Main Data").Range("D" & i) = Sheets("CM_MainData").Range("D" & j)
Sheets("Main Data").Range("E" & i) = Sheets("CM_MainData").Range("E" & j)
Sheets("Main Data").Range("F" & i) = Sheets("CM_MainData").Range("F" & j)
Sheets("Main Data").Range("G" & i) = Sheets("CM_MainData").Range("G" & j)
Sheets("Main Data").Range("H" & i) = Sheets("CM_MainData").Range("H" & j)
Sheets("Main Data").Range("I" & i) = Sheets("CM_MainData").Range("I" & j)
Sheets("Main Data").Range("J" & i) = Sheets("CM_MainData").Range("J" & j)
Sheets("Main Data").Range("K" & i) = Sheets("CM_MainData").Range("K" & j)
Sheets("Main Data").Range("L" & i) = Sheets("CM_MainData").Range("L" & j)
Sheets("Main Data").Range("M" & i) = Sheets("CM_MainData").Range("M" & j)
Sheets("Main Data").Range("N" & i) = Sheets("CM_MainData").Range("N" & j)
Sheets("Main Data").Range("O" & i) = Sheets("CM_MainData").Range("O" & j)
Sheets("Main Data").Range("P" & i) = Sheets("CM_MainData").Range("P" & j)
i = i + 1
j = j + 1
Wend
Worksheets("Input").Activate
Worksheets("Input").Select
MsgBox "Step 1 Completed"
End Sub