Solved

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

Posted on 2014-07-29
8
199 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

737 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