Below is a code that I have for a complicated model I created.
Each time I click the button to run the macro it takes roughly 30 seconds. I know it may not seem like that long of a time to wait, but when you have to click this button a lot of times it is not efficient. Can you guys look this over and recommend any changes that will increase the speed to run it. It should go without saying, but just in case, I can't change the actions of this macro.
Sub onedown()
Dim rw As Integer
Dim lastCol As Integer
ActiveWorkbook.Save
rw = Selection.Row + 1
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
Range("A1").SpecialCells (xlCellTypeBlanks)
Rows(rw).Insert CopyOrigin:=xlFormatFromLeftOrAbove
With Cells(rw, 1).Resize(, lastCol)
.Interior.ThemeColor = xlThemeColorDark1
.Borders.LineStyle = xlNone
End With
Range("E" & rw).FormulaR1C1 = Range("E" & rw - 1).FormulaR1C1
Range("H" & rw).FormulaR1C1 = Range("H" & rw - 1).FormulaR1C1
Range("L" & rw).FormulaR1C1 = Range("L" & rw - 1).FormulaR1C1
Range("P" & rw).FormulaR1C1 = Range("P" & rw - 1).FormulaR1C1
Range("Q" & rw).FormulaR1C1 = Range("Q" & rw - 1).FormulaR1C1
Range("R" & rw).FormulaR1C1 = Range("R" & rw - 1).FormulaR1C1
Range("X" & rw).FormulaR1C1 = Range("X" & rw - 1).FormulaR1C1
Range("Y" & rw).FormulaR1C1 = Range("Y" & rw - 1).FormulaR1C1
Range("Z" & rw).FormulaR1C1 = Range("Z" & rw - 1).FormulaR1C1
Range("AA" & rw).FormulaR1C1 = Range("AA" & rw - 1).FormulaR1C1
Range("AB" & rw).FormulaR1C1 = Range("AB" & rw - 1).FormulaR1C1
Range("AC" & rw).FormulaR1C1 = Range("AC" & rw - 1).FormulaR1C1
Range("AD" & rw).FormulaR1C1 = Range("AD" & rw - 1).FormulaR1C1
Range("AE" & rw).FormulaR1C1 = Range("AE" & rw - 1).FormulaR1C1
Range("AF" & rw).FormulaR1C1 = Range("AF" & rw - 1).FormulaR1C1
Range("AG" & rw).FormulaR1C1 = Range("AG" & rw - 1).FormulaR1C1
Range("AH" & rw).FormulaR1C1 = Range("AH" & rw - 1).FormulaR1C1
Range("AI" & rw).FormulaR1C1 = Range("AI" & rw - 1).FormulaR1C1
Range("AJ" & rw).FormulaR1C1 = Range("AJ" & rw - 1).FormulaR1C1
Range("AK" & rw).FormulaR1C1 = Range("AK" & rw - 1).FormulaR1C1
Range("AL" & rw).FormulaR1C1 = Range("AL" & rw - 1).FormulaR1C1
Range("AP" & rw).FormulaR1C1 = Range("AP" & rw - 1).FormulaR1C1
Range("AU" & rw).FormulaR1C1 = Range("AU" & rw + 1).FormulaR1C1
Range("AV" & rw).FormulaR1C1 = Range("AV" & rw + 1).FormulaR1C1
Range("AW" & rw).FormulaR1C1 = Range("AW" & rw + 1).FormulaR1C1
Range("AX" & rw).FormulaR1C1 = Range("AX" & rw + 1).FormulaR1C1
Range("AY" & rw).FormulaR1C1 = Range("AY" & rw + 1).FormulaR1C1
Range("AZ" & rw).FormulaR1C1 = Range("AZ" & rw + 1).FormulaR1C1
Range("BA" & rw).FormulaR1C1 = Range("BA" & rw + 1).FormulaR1C1
Range("BB" & rw).FormulaR1C1 = Range("BB" & rw + 1).FormulaR1C1
Range("BC" & rw).FormulaR1C1 = Range("BC" & rw + 1).FormulaR1C1
Range("BD" & rw).FormulaR1C1 = Range("BD" & rw + 1).FormulaR1C1
Range("BE" & rw).FormulaR1C1 = Range("BE" & rw + 1).FormulaR1C1
Range("BF" & rw).FormulaR1C1 = Range("BF" & rw + 1).FormulaR1C1
Range("BG" & rw).FormulaR1C1 = Range("BG" & rw + 1).FormulaR1C1
Range("BH" & rw).FormulaR1C1 = Range("BH" & rw + 1).FormulaR1C1
Range("BI" & rw).FormulaR1C1 = Range("BI" & rw + 1).FormulaR1C1
Range("I" & rw).Select
End Sub
Each time I click the button to run the macro it takes roughly 30 seconds. I know it may not seem like that long of a time to wait, but when you have to click this button a lot of times it is not efficient. Can you guys look this over and recommend any changes that will increase the speed to run it. It should go without saying, but just in case, I can't change the actions of this macro.
Sub onedown()
Dim rw As Integer
Dim lastCol As Integer
ActiveWorkbook.Save
rw = Selection.Row + 1
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
Range("A1").SpecialCells (xlCellTypeBlanks)
Rows(rw).Insert CopyOrigin:=xlFormatFromLeftOrAbove
With Cells(rw, 1).Resize(, lastCol)
.Interior.ThemeColor = xlThemeColorDark1
.Borders.LineStyle = xlNone
End With
Range("E" & rw).FormulaR1C1 = Range("E" & rw - 1).FormulaR1C1
Range("H" & rw).FormulaR1C1 = Range("H" & rw - 1).FormulaR1C1
Range("L" & rw).FormulaR1C1 = Range("L" & rw - 1).FormulaR1C1
Range("P" & rw).FormulaR1C1 = Range("P" & rw - 1).FormulaR1C1
Range("Q" & rw).FormulaR1C1 = Range("Q" & rw - 1).FormulaR1C1
Range("R" & rw).FormulaR1C1 = Range("R" & rw - 1).FormulaR1C1
Range("X" & rw).FormulaR1C1 = Range("X" & rw - 1).FormulaR1C1
Range("Y" & rw).FormulaR1C1 = Range("Y" & rw - 1).FormulaR1C1
Range("Z" & rw).FormulaR1C1 = Range("Z" & rw - 1).FormulaR1C1
Range("AA" & rw).FormulaR1C1 = Range("AA" & rw - 1).FormulaR1C1
Range("AB" & rw).FormulaR1C1 = Range("AB" & rw - 1).FormulaR1C1
Range("AC" & rw).FormulaR1C1 = Range("AC" & rw - 1).FormulaR1C1
Range("AD" & rw).FormulaR1C1 = Range("AD" & rw - 1).FormulaR1C1
Range("AE" & rw).FormulaR1C1 = Range("AE" & rw - 1).FormulaR1C1
Range("AF" & rw).FormulaR1C1 = Range("AF" & rw - 1).FormulaR1C1
Range("AG" & rw).FormulaR1C1 = Range("AG" & rw - 1).FormulaR1C1
Range("AH" & rw).FormulaR1C1 = Range("AH" & rw - 1).FormulaR1C1
Range("AI" & rw).FormulaR1C1 = Range("AI" & rw - 1).FormulaR1C1
Range("AJ" & rw).FormulaR1C1 = Range("AJ" & rw - 1).FormulaR1C1
Range("AK" & rw).FormulaR1C1 = Range("AK" & rw - 1).FormulaR1C1
Range("AL" & rw).FormulaR1C1 = Range("AL" & rw - 1).FormulaR1C1
Range("AP" & rw).FormulaR1C1 = Range("AP" & rw - 1).FormulaR1C1
Range("AU" & rw).FormulaR1C1 = Range("AU" & rw + 1).FormulaR1C1
Range("AV" & rw).FormulaR1C1 = Range("AV" & rw + 1).FormulaR1C1
Range("AW" & rw).FormulaR1C1 = Range("AW" & rw + 1).FormulaR1C1
Range("AX" & rw).FormulaR1C1 = Range("AX" & rw + 1).FormulaR1C1
Range("AY" & rw).FormulaR1C1 = Range("AY" & rw + 1).FormulaR1C1
Range("AZ" & rw).FormulaR1C1 = Range("AZ" & rw + 1).FormulaR1C1
Range("BA" & rw).FormulaR1C1 = Range("BA" & rw + 1).FormulaR1C1
Range("BB" & rw).FormulaR1C1 = Range("BB" & rw + 1).FormulaR1C1
Range("BC" & rw).FormulaR1C1 = Range("BC" & rw + 1).FormulaR1C1
Range("BD" & rw).FormulaR1C1 = Range("BD" & rw + 1).FormulaR1C1
Range("BE" & rw).FormulaR1C1 = Range("BE" & rw + 1).FormulaR1C1
Range("BF" & rw).FormulaR1C1 = Range("BF" & rw + 1).FormulaR1C1
Range("BG" & rw).FormulaR1C1 = Range("BG" & rw + 1).FormulaR1C1
Range("BH" & rw).FormulaR1C1 = Range("BH" & rw + 1).FormulaR1C1
Range("BI" & rw).FormulaR1C1 = Range("BI" & rw + 1).FormulaR1C1
Range("I" & rw).Select
End Sub
Last edited: