Solved

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

Posted on 2014-07-29
8
198 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
  • 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 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Lookup - Vlookup 9 46
Excel 2013 Find and copy duplicates depending of qty values 7 30
Excel Named Range 31 44
need 2017 datas one by one using macro 12 36
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

756 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