Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Format underline a range

Posted on 2016-08-11
2
Medium Priority
?
120 Views
Last Modified: 2016-08-12
This is related to solved question https://www.experts-exchange.com/questions/28962735/Make-sub-to-format-and-total-ranges.html

For convenience, I'm attaching the same .xlsx files.

Add bottom borders under 2 total rows
I'd like to add bottom borders on the last 2 rows of each group as shown. I tried to change the code here but it just underlines the first cell of the 2nd row. I'd like to underline that whole row and the cells directly above that.

Add bottom borders under 2 total rows WRONG
Sub AddGroupAndTotalsAndUnderlines()
'
' Run after SeparateGroups
' Put BM's name on bolded line, and add bolded totals for each group.
' Also underline totals. It doesn't work correctly. Just 1 cell is underlined.
'
'
Dim rng As Range
Application.ScreenUpdating = False
For Each rng In Range("A:A").SpecialCells(xlCellTypeConstants, 2).Areas
    If rng.Cells(1).Row <> 1 Then
        rng.Cells(1).Copy rng.Cells(1).Offset(-1, 2)
        With rng.Cells(1).Offset(-1, 2).Font
            .Bold = True
            .Size = 14
            .Name = "Calibri"
        End With
        rng.Cells(rng.Rows.Count + 1).Offset(0, 5).Resize(, 8).FormulaR1C1 = "=SUM(R[-" & rng.Rows.Count & "]C:R[-1]C)"
        rng.Cells(rng.Rows.Count + 1).Offset(0, 5).Resize(, 8).Font.Bold = True
        With rng.Cells(rng.Rows.Count + 1).Offset(0, 5).Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
    End If
Next rng
Application.ScreenUpdating = True
End Sub

Open in new window


For my edification, I'd appreciate also an explanation of my error and how you fixed it. 8-)
Before.xlsx
After.xlsx
0
Comment
Question by:NVIT
[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
2 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 41753344
Change this line:
With rng.Cells(rng.Rows.Count + 1).Offset(0, 5).Borders(xlEdgeBottom)

Open in new window

to this:
With rng.Cells(rng.Rows.Count + 1).Offset(0, 5).Resize(, 8).Borders(xlEdgeBottom)

Open in new window

0
 
LVL 33

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 2000 total points
ID: 41753376
Please try this.....

Sub AddGroupAndTotalsAndUnderlines()
Dim rng As Range
Application.ScreenUpdating = False
For Each rng In Range("A:A").SpecialCells(xlCellTypeConstants, 2).Areas
    If rng.Cells(1).Row <> 1 Then
        rng.Cells(1).Copy rng.Cells(1).Offset(-1, 2)
        With rng.Cells(1).Offset(-1, 2).Font
            .Bold = True
            .Size = 14
            .Name = "Calibri"
        End With
        rng.Cells(rng.Rows.Count + 1).Offset(0, 5).Resize(, 8).FormulaR1C1 = "=SUM(R[-" & rng.Rows.Count & "]C:R[-1]C)"
        rng.Cells(rng.Rows.Count + 1).Offset(0, 5).Resize(, 8).Font.Bold = True
        With rng.Cells(rng.Rows.Count + 1).Offset(0, 5).Resize(, 8).Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThin
        End With
        With rng.Cells(rng.Rows.Count + 1).Offset(0, 5).Resize(, 8).Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThin
        End With
    
    End If
Next rng
Application.ScreenUpdating = True
End Sub

Open in new window

0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

610 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