Thick borders in VBA

Ginger Grange

New Member
Joined
Oct 1, 2021
Messages
4
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi there

Long time fan first time poster.

I am trying to set up a macro that works for just one column. If the cell within that column has 1 of 4 letters within it (A, B, C & U) then the side border of that cell is colored accordingly but with a thick side. Unfortunately, conditional formatting only gives a thin border which is not that easy to see.

Can anyone help? I am competent at excel but have never done VBA before

many thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi & welcome to MrExcel.
A few questions.
1) What column do you want it work on?
2) What is the first row in that column?
3) What colour should the border be?
 
Upvote 0
Hi & welcome to MrExcel.
A few questions.
1) What column do you want it work on?
2) What is the first row in that column?
3) What colour should the border be?
Hi Fluff, thank you for getting back to me so quickly

its column N starting at cell 3 down to cell say 300
Colours are A= green B=Blue C=gray U=red
 
Upvote 0
Ok, how about
VBA Code:
Sub GingerGrange()
   Dim Cl As Range
   Dim Clr As Long
   
   For Each Cl In Range("N3", Range("N" & Rows.Count).End(xlUp))
      If InStr(1, Cl.Value, "A", vbTextCompare) > 0 Then
         Clr = 5287936
      ElseIf InStr(1, Cl.Value, "B", vbTextCompare) > 0 Then
         Clr = 12611584
      ElseIf InStr(1, Cl.Value, "C", vbTextCompare) > 0 Then
         Clr = 8421504
      ElseIf InStr(1, Cl.Value, "U", vbTextCompare) > 0 Then
         Clr = 255
      End If
      If Clr <> 0 Then
         With Cl.Borders(xlEdgeRight)
            .Color = Clr
            .Weight = xlThick
         End With
         Clr = 0
      End If
   Next Cl
End Sub
 
Upvote 0
Ok, how about
VBA Code:
Sub GingerGrange()
   Dim Cl As Range
   Dim Clr As Long
  
   For Each Cl In Range("N3", Range("N" & Rows.Count).End(xlUp))
      If InStr(1, Cl.Value, "A", vbTextCompare) > 0 Then
         Clr = 5287936
      ElseIf InStr(1, Cl.Value, "B", vbTextCompare) > 0 Then
         Clr = 12611584
      ElseIf InStr(1, Cl.Value, "C", vbTextCompare) > 0 Then
         Clr = 8421504
      ElseIf InStr(1, Cl.Value, "U", vbTextCompare) > 0 Then
         Clr = 255
      End If
      If Clr <> 0 Then
         With Cl.Borders(xlEdgeRight)
            .Color = Clr
            .Weight = xlThick
         End With
         Clr = 0
      End If
   Next Cl
End Sub
Again thank you for getting back to me. for some reason, it doesn't seem to work. forgive me I am very new to VBA..
 
Upvote 0
In that way isn't it working?
 
Upvote 0
What part of the code is highlighted?
 
Upvote 0

Forum statistics

Threads
1,213,479
Messages
6,113,895
Members
448,530
Latest member
yatong2008

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