Hi folks,
Through playing around with the macro recorder and looking at other macros, I have written the following:
Sub Fill_Gaps_Spreadsheet()
' Interrupts Automatic Calculation, ScreenUpdating and StatusBar
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
' Converts column D to number
Range("d2:D70000").Select
With Selection
Selection.NumberFormat = "General"
.Value = .Value
End With
' Replaces current blank unit price with start of year unit price
Range("Q2:Q70000").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=RC[31]"
' Calculates Min Stock Value & SOH Value for current range
Columns("R:R").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=RC[-1]*RC[-10]"
Range("T:T").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=RC[-3]*RC[-9]"
' Imports old stock
Range("AM2:AM70000").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=INDEX(OldMinMax!R2C4:R129556C4,MATCH(RC[-38]&RC[-35],OldMinMax!R2C1:R129556C1,0))"
' Import current min where old stock is not available
Columns("AM2:AM70000").Select
Selection.SpecialCells(xlCellTypeFormulas, 16).Select
Selection.FormulaR1C1 = "=RC[-31]"
' Imports current min where SOH is Nil
Range("h2:h70000").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=INDEX(CurrentMinMax!R2C4:R100000C4,MATCH(RC[-7]&RC[-4],CurrentMinMax!R2C1:R100000C1,0))"
' Removes index&match formula on old & current min
Dim smallrng As Range
For Each smallrng In Range("AM2:AM70000,H2:H70000,Q2:Q70000,R2:R70000,T2:T70000").Areas
With smallrng
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
Application.CutCopyMode = False
Next smallrng
' Restores Automatic Calculation, ScreenUpdating and StatusBar
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
End Sub
My only issue is that if one of the elements of the macro does not apply (eg there are no blank cells in R:R), I have an error and the macro does not run.
Can someone please tell me what to add to bypass this problem and allow the macro to continue running? Also, if any of you can see a way to speed up the processing of the macro (which takes quite a bit of time at the moment), I'll be very grateful :-)
Thanks in advance.
S
Bookmarks