Help Adding Top Border and Back ground Color to Macro and Also help with #DIV/0!

maxf24

New Member
Joined
Mar 12, 2014
Messages
25
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
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top