Hi all,
I've recently started using VBA and I've done a relatively simple macro, but it's using Do Loops. When I ran this macro over my entire range (around 4500 cells) it took 23 minutes. My code is below, highlighted in red is the text that I need to ideally change so that my code runs faster. Does anyone have any suggestions?
-------------------------------------------
Sub WeekdayColumn()
'
' Add weekday column into incident data
'
'
Sheets("Incident Data").Select
Dim RowCount As Integer
RowCount = ActiveSheet.Range("A1").End(xlDown).row
Range("P1").Select
ActiveCell.FormulaR1C1 = RowCount
Application.ScreenUpdating = False
Range("A1").Select
Selection.End(xlToRight).Select
Selection.EntireColumn.ClearContents
ActiveCell.Offset(1, 0).Range("A1").Select
Dim i As Integer, StartTime As Date
StartTime = Now()
Call WeekdayFormulaDoLoop
ActiveCell.Offset(-1, 0).Range("A1").ClearContents
Range("A1").Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "Weekday"
Range("P1").Select
Selection.ClearContents
MsgBox Format(Now() - StartTime, "hh:mm:ss")
End Sub
Sub WeekdayFormulaDoLoop()
'
' WeekdayFormula Macro
'
Do Until ActiveCell.Offset(0, -1) = ""
For i = 1 To Range("P1")
Application.StatusBar = "Rows to Process..." & Range("P1") - i
ActiveCell.FormulaR1C1 = "=WEEKDAY(RC[-12],2)"
ActiveCell.Offset(1, 0).Range("A1").Select
Next i
Loop
Application.StatusBar = False
ActiveCell.ClearContents
End Sub
-------------------------------------------
Thanks!
Bookmarks