Cell formatting based on cell value

77highland

New Member
Joined
Nov 11, 2013
Messages
7
Hello everyone - First ever post for me.

I have a worksheet that looks like the following:


[TABLE="class: grid, width: 500, align: left"]
<TBODY>[TR]
[TD]Date Occurred
[/TD]
[TD]Asset Number
[/TD]
[TD]Coach Number
[/TD]
[TD]Fault Description
[/TD]
[TD]Priority
[/TD]
[/TR]
[TR]
[TD]22/11/13
[/TD]
[TD]395001
[/TD]
[TD]39016
[/TD]
[TD]Headlight Failure
[/TD]
[TD]1b
[/TD]
[/TR]
[TR]
[TD]13/09/13
[/TD]
[TD]395001
[/TD]
[TD]39014
[/TD]
[TD]HVAC Vibration
[/TD]
[TD]4a
[/TD]
[/TR]
[TR]
[TD]02/11/13
[/TD]
[TD]395009
[/TD]
[TD]39095
[/TD]
[TD]Window Smashed
[/TD]
[TD]2a
[/TD]
[/TR]
[TR]
[TD]05/11/13
[/TD]
[TD]395009
[/TD]
[TD]39092
[/TD]
[TD]Brake Pad Change
[/TD]
[TD]1a
[/TD]
[/TR]
[TR]
[TD]08/11/13
[/TD]
[TD]395015
[/TD]
[TD]39154
[/TD]
[TD]Toilet Fault
[/TD]
[TD]2b
[/TD]
[/TR]
</TBODY>[/TABLE]










I need to automatically apply a thick bottom boarder to each row of the final group of asset numbers. I.e:- Underline row 3 as 3b contains the final '395001' and row 5 as 5b contains the final '395009'.

This data is forver changing so would be useful if I could run a macro (or CF?) using an on/off button or tick box.

Thanks.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi 77, welcome to the forum.

Give this a try. Note that final group asset number may be a single number.

Regards,
Howard

Code:
Option Explicit

Sub uLineIt()

Dim c As Range
Dim lRow As Long

lRow = Range("B2:B6").End(xlDown).Row

Range("A2:E" & lRow).Select
  Selection.Borders(xlEdgeBottom).LineStyle = xlNone
  Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

Application.ScreenUpdating = False

For Each c In Range("B2:B" & lRow)
  If c.Offset(1, 0) <> c Then
    c.Offset(0, -1).Resize(1, 5).Select
    
      With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlMedium
      End With

  End If
  
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
This can also be done with conditional formatting, except that conditional formatting doesn't have the option for thick borders. If you wanted regular borders, you could do something like this:


Excel 2010
ABCDE
1Date OccurredAsset NumberCoach NumberFault DescriptionPriority
222/11/1339500139016Headlight Failure1b
313/09/1339500139014HVAC Vibration4a
42/11/201339500939095Window Smashed2a
55/11/201339500939092Brake Pad Change1a
65/12/201339500939092Brake Pad Change1a
78/11/201339501539154Toilet Fault2b
Sheet105


1) Highlight the entire range
2) Go to conditional formatting --> New Rule --> Use formula
3) Use this formula: =$B2<>$B1
4) Select Format --> Border --> Top border
5) Ok, Ok, Ok.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top