Link to home
Start Free TrialLog in
Avatar of Wilder1626
Wilder1626Flag for Canada

asked on

Add border in cell if

Hello all

I have a code where i add border in cell if there is a value in it from range A4 to K6500

'Add Border
Dim c As Range
For Each c In Range("A4:K6500")
    If Not IsEmpty(c) Then
      c.Borders(xlEdgeLeft).LineStyle = xlContinuous
      c.Borders(xlEdgeTop).LineStyle = xlContinuous
      c.Borders(xlEdgeBottom).LineStyle = xlContinuous
      c.Borders(xlEdgeRight).LineStyle = xlContinuous
    End If
Next c
 

Open in new window


But now, i also want to add a border in cell from Range L4 to AX6500 if the value from column K of the same row has a value in the cell.

How can i do that?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of jppinto
jppinto
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
where it reads 65 on the code, should be 6500 (used 65 for testing purpose!)
Avatar of Wilder1626

ASKER

This is so good,

Thanks for your help
Sub test()
'Add Border
Dim c As Range
Dim c2 As Range
For Each c In Range("L4:AX6500")
    Set c2 = Range("K" & c.Row)
    If Not IsEmpty(c2) Then
      c.Borders(xlEdgeLeft).LineStyle = xlContinuous
      c.Borders(xlEdgeTop).LineStyle = xlContinuous
      c.Borders(xlEdgeBottom).LineStyle = xlContinuous
      c.Borders(xlEdgeRight).LineStyle = xlContinuous
    End If
Next c
End Sub

Open in new window


Enjoy :)
Avatar of Norie
Norie

I know this is closed but for what it's worth this could be done with conditional formatting(CF).

The first condition could be handled by the No Blanks option and the 2nd condition with a simple formula =$K4<>"".

The only problem would be if you wanted a thick border, which isn't available in CF.