Help Adding text to existing Macro

maxf24

New Member
Joined
Mar 12, 2014
Messages
25
I have a macro I use daily and want to add a few things to it. I had a ton of help with what I have now (code below) and tried to add the stuff myself, but it turned into a disaster. So back to the drawing board. Any help is greatly appreciated!

What I've been trying to do is add titles under/beside the formulas:
  • New-1 =“Annual”
    .Font.Bold = True
  • New-2 =“kWh”
  • New-3 =“peak kW”
  • New-4 =“TDSP”
  • New-5 =“Avg. TDSP chrg”
  • New-6 =“load factor”
  • *New-7 =“(Power factor charges only >250kW & <95% PF)”
    .Font.Italic = True
.MergeCells = True
.HorizontalAlignment = xlCenter

  • *New-8 =“(higher load factor = lower delivery charges)”
    .Font.Italic = True
.MergeCells = True
.HorizontalAlignment = xlCenter
*New-7 & New-8 merge w/ K,L,N,O,P (M is not visible on the worksheet.)

Example:
[TABLE="width: 500"]
<tbody>[TR]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[TD]K[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Formula[/TD]
[TD]Formula[/TD]
[TD]Formula[/TD]
[TD]Formula[/TD]
[TD]Formula[/TD]
[TD]New-7[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]New-1[/TD]
[TD]New-2[/TD]
[TD]New-3[/TD]
[TD]New-4[/TD]
[TD]New-5[/TD]
[TD]New-6[/TD]
[TD]New-8[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Formula[/TD]
[TD]Formula[/TD]
[TD]Formula[/TD]
[TD]Formula[/TD]
[TD]Formula[/TD]
[TD]New-7[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]New-1[/TD]
[TD]New-2[/TD]
[TD]New-3[/TD]
[TD]New-4[/TD]
[TD]New-5[/TD]
[TD]New-6[/TD]
[TD]New-8[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Formula[/TD]
[TD]Formula[/TD]
[TD]Formula[/TD]
[TD]Formula[/TD]
[TD]Formula[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Code:
Sub InsertTotals()
 
    Dim lStartSample As Long, lEndSample As Long
    Dim lSampleRows As Long, lEnd As Long
    Const GAP = 3
    Dim sFormula As String
   
    sFormula = "="
    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("F" & lEndSample).FormulaR1C1 = "=Sum(R[-" & lSampleRows & "]C:R[-1]C)"
        Range("G" & lEndSample).FormulaR1C1 = "=Max(R[-" & lSampleRows & "]C:R[-1]C)"
        With Range("H" & lEndSample)
            .Style = "Currency"
            .NumberFormat = "$#,###"
            .FormulaR1C1 = "=sum(R[-" & lSampleRows & "]C:R[-1]C)"
        End With
        With Range("I" & lEndSample)
            .Style = "Currency"
            .NumberFormat = "$#,###.####"
            .FormulaR1C1 = "=IF(RC[-3]=0,"""",RC[-1]/RC[-3])"
        End With
        With Range("J" & lEndSample)
            .Style = "Percent"
            .FormulaR1C1 = "=IF(RC[-3]=0,"""",RC[-4]/(RC[-3]*8760))"
       
        End With
        sFormula = sFormula & "R" & lEndSample & "C+"
        lStartSample = lEndSample + GAP
        With Range("F" & lEndSample).Resize(, 5)
    .Borders(xlEdgeLeft).Weight = xlMedium
    .Borders(xlEdgeRight).Weight = xlMedium
    .Borders(xlEdgeTop).Weight = xlMedium
    .Borders(xlEdgeBottom).Weight = xlMedium
.Interior.Color = RGB(0, 255, 127)
        End With
       With Range("F" & lEndSample).Resize(, 5)
.HorizontalAlignment = xlCenter
End With
 
    Loop
    Rows(lEndSample + 2).Font.Bold = True
    sFormula = Left(sFormula, Len(sFormula) - 1)
    Range("H" & lEndSample + 2).Style = "Currency"
        Range("H" & lEndSample + 2).NumberFormat = "$#,###"
        Range("I" & lEndSample + 2).Style = "Currency"
        Range("I" & lEndSample + 2).NumberFormat = "$#,###.####"
        Range("J" & lEndSample + 2).Style = "Percent"
  Range("F" & lEndSample + 2).FormulaR1C1 = sFormula
    Range("G" & lEndSample + 2).FormulaR1C1 = sFormula
    Range("H" & lEndSample + 2).FormulaR1C1 = sFormula
    Range("I" & lEndSample + 2).FormulaR1C1 = "=IF(RC[-3]=0,"""",RC[-1]/RC[-3])"
    Range("J" & lEndSample + 2).FormulaR1C1 = "=IF(RC[-3]=0,"""",RC[-4]/(RC[-3]*8760))"
    With Range("F" & lEndSample + 2).Resize(, 5)
    .Borders(xlEdgeLeft).Weight = xlMedium
    .Borders(xlEdgeRight).Weight = xlMedium
    .Borders(xlEdgeTop).Weight = xlMedium
    .Bord 
 ers(xlEdgeBottom).Weight = xlMedium
    .Borders(xlInsideVertical).Weight = xlMedium
    .Interior.Color = RGB(0, 255, 127)
End With
With Range("F" & lEndSample + 2).Resize(, 5)
.HorizontalAlignment = xlCenter
End With
 End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,223,104
Messages
6,170,126
Members
452,303
Latest member
c4cstore

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