?
Solved

How to insert a thick line after integer row in Excel.

Posted on 2014-07-29
8
Medium Priority
?
202 Views
Last Modified: 2014-07-31
I have an excel document. I have a macro doing a ton of formatting. One of the formatting options organizes the data by names in Column A and then after each name change it adds three spaces.

I'm looking for an additional macro code to then go to columns k-y and for each new person, sum the columns. Each month the row totals will change.

Example Excel Attached. The rows in yellow are the rows i need to create via VBA script. Essentially some how get the script to read down the column selected (B) and when it sees a break in numbers, insert the formula. Then continue down. The number of rows will always be different although in this one its 2 then 1 then 3.
0
Comment
Question by:Brandon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40227714
Attachment? :-)
0
 
LVL 3

Author Comment

by:Brandon
ID: 40227727
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40227872
The formulas in J, K, L, & M need to remain as they are, just copied down so that they apply on the total row.  The rest should be SUM() formulas.

I assume you want a thick border above the total row, but no other formatting, correct?

-Glenn
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40227940
Attached is a macro-enabled workbook with the following code that will add subtotals after each set of names (Add_Totals):
Sub Add_Totals()
    Dim rng As Range
    Dim cl As Object
    Dim r, c, x As Integer
    Dim strName As String
    Set rng = Range("A1:A" & Cells.SpecialCells(xlLastCell).Row)
    For Each cl In rng
        If (cl.Value = "") And (strName <> "") Then 'add total
            For c = 1 To 8
                cl.Offset(0, c).FormulaR1C1 = "=SUM(R[-" & x & "]C:R[-1]C)"
            Next c
            For c = 13 To 15
                cl.Offset(0, c).FormulaR1C1 = "=SUM(R[-" & x & "]C:R[-1]C)"
            Next c
            r = cl.Row
            cl.Offset(0, 9).Formula = "=IFERROR(I" & r & "/B" & r & ","""")"
            cl.Offset(0, 10).Formula = "=IFERROR((C" & r & "-E" & r & ")/C" & r & ","""")"
            cl.Offset(0, 11).Formula = "=IFERROR((D" & r & "-G" & r & ")/D" & r & ","""")"
            cl.Offset(0, 12).Formula = "=IFERROR(MIN(0.25,(C" & r & "-E" & r & "-F" & r & ")/C" & r & "),0.25)"
            strName = cl.Value 'should be blank
            x = 0
            With Range(cl.Offset(0, 1), cl.Offset(0, 15)).Borders(xlEdgeTop)
                .LineStyle = xlContinuous
                .ColorIndex = xlAutomatic
                .TintAndShade = 0
                .Weight = xlMedium
            End With
        Else
            strName = cl.Value
            If strName <> "" Then x = x + 1
        End If
    Next cl
End Sub

Open in new window


Note that I also changed the formulas in columns J through M to use the IFERROR function, which is significantly shorter:
J1: =IFERROR(I1/B1,"")
K1: =IFERROR((C1-E1)/C1,"")
L1: =IFERROR((D1-G1)/D1,"")
M1: =IFERROR(MIN(0.25,(C1-E1-F1)/C1),0.25)

You may want to change your existing macro that builds these formulas to use the IFERROR versions here.

Regards,
-Glenn
EE-Need-VBA.xlsm
0
 
LVL 3

Author Comment

by:Brandon
ID: 40232524
Increased points since there will be at least one followup. Thanks for the changes, i'll implement.

This worked well with a couple of exceptions that are my fault.

the first three rows are header rows so this should start at A4. Actually it should start at G4 and provide the calculations for G-U and all the way down to the end.

Does this make sense?
0
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 2000 total points
ID: 40232709
Okay...code and example file adjusted for change in layout.  Let me know if you have any further questions or issues.

Regards,
-Glenn
EE-Need-VBA.xlsm
0
 
LVL 3

Author Comment

by:Brandon
ID: 40232733
AMAZING!!
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40232870
I'm glad I could help.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question