I tried to find relevant topics on the forum but none of them seems to fit exactly my issue. Quick background: I am a pretty strong excel user but quite limited when it comes to macros, which I use mostly for time saving activities like handling large data and copy/pasting formulas into values to save space.
I also use this opportunity to thank all of you anonymous users who have helped me a lot without knowing it ;)
In this case my macro has the following purpose:
File set-up:
- One tab with the raw data extracted from my system (call it "SheetRAW")
- One tab to copy/paste/clean the raw data and add additional info from master file (call it "SheetDB")
Macro steps:
- Copy formula in SheetDB row 1 (linked to SheetRAW) and drag down to as many rows as needed
- Calculate current sheet only
- Copy paste everything into values starting row 2 downwards (do not erase row 1 with formulas)
I have a macro that works perfectly fine except when the number of rows in SheetRAW is too large (say more than 300k or 400k rows). I would like to know if there is any way to modify the code to avoid that issue?
The workaround I might need to use otherwise is to "fragment" my current macro to only calculate the first 100k or 200k rows, then repeat for the rest.
Note that I do deactivate the ScreenUpdating at the beginning and that my excel is always set to manual calculation.
Application.ScreenUpdating = False
ActiveSheet.Outline.ShowLevels RowLevels:=8, ColumnLevels:=8
ActiveSheet.Calculate
Dim iRow As Long
iRow = Application.Max(Range("T1")) - 1
'Delete previous data
Range("A9").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).ClearContents
'Update DB (all rows) for columns A-G
Range("A7:G7").Select
Selection.Copy
Range("A9:G9").Select
Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(iRow, 0)).Select
ActiveSheet.Paste
ActiveSheet.Calculate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'Update DB (all rows) for columns H-T
Range("H7:T7").Select
Selection.Copy
Range("H9:T9").Select
Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(iRow, 0)).Select
ActiveSheet.Paste
ActiveSheet.Calculate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'Update DB (all rows) for columns U-AH
Range("U7:AH7").Select
Selection.Copy
Range("U9:AH9").Select
Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(iRow, 0)).Select
ActiveSheet.Paste
ActiveSheet.Calculate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWindow.ScrollRow = 1
Range("A1").Select
ActiveSheet.Outline.ShowLevels RowLevels:=1, ColumnLevels:=1
Application.ScreenUpdating = True