?
Solved

VBA simple formatting qstn

Posted on 2016-11-07
4
Medium Priority
?
66 Views
Last Modified: 2016-11-08
I have 20 columns on my Sheet1
Columns A-D are filled with Location, Name1, Name2, Cost
the rest of Columns is just data per month.
I already have a Range and VBA to put grid all around my ranged cells.
I need a VBA code to put bolded line everytime Name1 (Column B) changes - so user can see "blocks" of data clearly.
Bolded line on the bottom of the last occurance of Name1
So if there is John Doe, Bill Smith...
After John Doe there will be a horizontal bolded line going all thru Col A thru Z (whatever 20th Col is)
0
Comment
Question by:CABRLU63
[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
4 Comments
 
LVL 32

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41878118
You may try something like this.....
Sub Formatting()
Dim lr As Long, lc As Long, i As Long
lr = Cells(Rows.Count, 2).End(xlUp).Row
lc = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 2 To lr
    If Cells(i, 2) <> Cells(i + 1, 2) Then
        With Range(Cells(i, 1), Cells(i, lc)).Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlMedium
        End With
    End If
Next i
End Sub

Open in new window

0
 
LVL 32

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 2000 total points
ID: 41878120
Or better to remove the existing bottom lines before running the code in case you run the code after new data added or edited.

Sub Formatting()
Dim lr As Long, lc As Long, i As Long
lr = Cells(Rows.Count, 2).End(xlUp).Row
lc = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 2 To lr
    Range(Cells(i, 1), Cells(i, lc)).Borders(xlEdgeBottom).LineStyle = xlNone
Next i
For i = 2 To lr
    If Cells(i, 2) <> Cells(i + 1, 2) Then
        With Range(Cells(i, 1), Cells(i, lc)).Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlMedium
        End With
    End If
Next i
End Sub

Open in new window

0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 41878514
I realise that this suggestion changes the way you are working but I am going to throw it out there anyway.

Instead of masses of columns, you could use a datagrid format with the following columns:
Location,
Name1,
Name2,
Cost,
Value,
Month.

The value and month columns would replace your multiple columns. Rather than a column for each month there would be one column and in that column you specify the month or even the actual date on which the value has occurred. This would mean that there are multiple lines per Location/Name etc.

With the data in this format you could then use a Pivot Table to summarise the data and the formatting of the Pivot Table can be set so that there is clear delineation between names etc and would adjust each time the Pivot Table is refreshed.
1
 

Author Closing Comment

by:CABRLU63
ID: 41879241
Rob Henson, I can't use Pivots. Not feasible for this project.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

771 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