VBA code formatting based on criterion

jakobt

Active Member
Joined
May 31, 2010
Messages
337
In column C is a list of account numbers. After account 4999999, I want to insert a thick black underline from column B to K.
Is it possible to write VBA code for this.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Will there only be one occurrence of that account number, or can it appear multiple times?
 
Upvote 0
Is VBA really required?
I ask because this is pretty simple to do without VBA using Conditional Formatting.
You can actually get the VBA code for that Conditional Formatting by turning on the Macro Recorder, and recording yourself applying the Conditional Formatting manually.
 
Upvote 0
Yes, this is part of a bigger VBA tune up of a spreadsheet. Would really like this code to work.
 
Upvote 0
Yes, this is part of a bigger VBA tune up of a spreadsheet. Would really like this code to work.
Did you try what I suggested? It should give you the VBA code that you require.

You can actually get the VBA code for that Conditional Formatting by turning on the Macro Recorder, and recording yourself applying the Conditional Formatting manually.
 
Upvote 0
It is not for sure the account 4999999 will exist in the list. The border should be betwen account 4xxxxxx and 5xxxxxx.
 
Upvote 0
As long as it is always increasing, you could just check if the current row is less than or equal to 4999999 and the next row is more than that.
So, you would select columns B-K and enter this Conditional Formatting formula:
=AND($C1
< =4999999,$C2>4999999)
and choose your underline format.
(remove the spaces from either side of the less than sign, that is just needed so the forum doesn't render it as HTML code and mess up the post).

Turn on the Macro Recorder and before your steps, and you will have your VBA code.
 
Last edited:
Upvote 0
How about
Code:
Sub AddBorder()
   Dim Rng As Range
   With Range("C1:C" & Rows.Count - 1)
      .AutoFilter 1, ">=" & 5000000
      Set Rng = .Offset(1).SpecialCells(xlVisible)(1)
      Rng.Offset(-1, -1).Resize(, 10).Borders(xlEdgeBottom).Weight = xlMedium
      .AutoFilter
   End With
End Sub
This assumes that the account numbers will be in ascending order
 
Last edited:
Upvote 0
Not sure who you are referring to, but glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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