Below is my current Macro, and I could use some help with a few things.
1) For each F,G,H,I,J end sample ranges that use the formulas, I want a Medium thickness, continuous, top Border. Also, I would like the cell to be highlighted yellow.
2) Sometimes the J column formula will show up as #DIV/0! is there any way I can just clear this cell to blank when that happens?
-reason it shows up as this is because G formula will end up 0 due to not being used one month, so the formula in J is F/(G*8760) and will show up as #DIV/0!
Any help would be greatly appreciated, and I've tried everything and I am new to VBA/Coding.
Sub InsertFormulae()
Dim lStartSample As Long, lEndSample As Long
Dim lSampleRows As Long, lEnd As Long
Const GAP = 2
lStartSample = 2
lEnd = Range("F" & Rows.Count).End(xlUp).Row
Do While lStartSample <= lEnd
lEndSample = Range("F" & lStartSample).End(xlDown).Row + 1
lSampleRows = lEndSample - lStartSample
Rows(lEndSample).Font.Bold = True
Range("H" & lEndSample).Style = "Currency"
Range("H" & lEndSample).NumberFormat = "$#,###"
Range("I" & lEndSample).Style = "Currency"
Range("I" & lEndSample).NumberFormat = "$#,###.####"
Range("J" & lEndSample).Style = "Percent"
Range("F" & lEndSample).FormulaR1C1 = "=Sum(R[-" & lSampleRows & "]C:R[-1]C)"
Range("G" & lEndSample).FormulaR1C1 = "=Max(R[-" & lSampleRows & "]C:R[-1]C)"
Range("H" & lEndSample).FormulaR1C1 = "=sum(R[-" & lSampleRows & "]C:R[-1]C)"
Range("I" & lEndSample).FormulaR1C1 = "=RC[-1]/RC[-3]"
Range("J" & lEndSample).FormulaR1C1 = "=RC[-4]/(RC[-3]*8760)"
lStartSample = lEndSample + GAP
Loop
End Sub
1) For each F,G,H,I,J end sample ranges that use the formulas, I want a Medium thickness, continuous, top Border. Also, I would like the cell to be highlighted yellow.
2) Sometimes the J column formula will show up as #DIV/0! is there any way I can just clear this cell to blank when that happens?
-reason it shows up as this is because G formula will end up 0 due to not being used one month, so the formula in J is F/(G*8760) and will show up as #DIV/0!
Any help would be greatly appreciated, and I've tried everything and I am new to VBA/Coding.
Sub InsertFormulae()
Dim lStartSample As Long, lEndSample As Long
Dim lSampleRows As Long, lEnd As Long
Const GAP = 2
lStartSample = 2
lEnd = Range("F" & Rows.Count).End(xlUp).Row
Do While lStartSample <= lEnd
lEndSample = Range("F" & lStartSample).End(xlDown).Row + 1
lSampleRows = lEndSample - lStartSample
Rows(lEndSample).Font.Bold = True
Range("H" & lEndSample).Style = "Currency"
Range("H" & lEndSample).NumberFormat = "$#,###"
Range("I" & lEndSample).Style = "Currency"
Range("I" & lEndSample).NumberFormat = "$#,###.####"
Range("J" & lEndSample).Style = "Percent"
Range("F" & lEndSample).FormulaR1C1 = "=Sum(R[-" & lSampleRows & "]C:R[-1]C)"
Range("G" & lEndSample).FormulaR1C1 = "=Max(R[-" & lSampleRows & "]C:R[-1]C)"
Range("H" & lEndSample).FormulaR1C1 = "=sum(R[-" & lSampleRows & "]C:R[-1]C)"
Range("I" & lEndSample).FormulaR1C1 = "=RC[-1]/RC[-3]"
Range("J" & lEndSample).FormulaR1C1 = "=RC[-4]/(RC[-3]*8760)"
lStartSample = lEndSample + GAP
Loop
End Sub