Adding borders around formula values

Majawat

New Member
Joined
Jun 14, 2011
Messages
49
The F column has this following code:
Code:
=IF(ISERROR(VLOOKUP(A7,Beers,2,FALSE)),"",IF(VLOOKUP(A7,Beers,2,FALSE)=0,"",VLOOKUP(A7,Beers,2,FALSE)))

I need a VBA script that only creates a border around those cells that evaulate to a value and not ""

This is the code I've tried:
Code:
    Dim LastRating
    LastRating = Cells(Cells.Rows.Count, "A").End(xlUp).Row
 
    On Error Resume Next
    Range("F4:F" & LastRating).SpecialCells(xlNumbers).Select
 
    Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
    Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
    Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
    Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
    Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
This doesn't border around anything at all. When I use SpecialCells(xlFormulas) it border around everything.

The values that the VLOOKUP should possibly evaluate to are "", 1-10 if that helps. I'll gladly provide any more information as necessary.

Any help would be greatly appreciated!

Also, I know I could do the formatting with a much more elegant With statement, but for other reasons, I'd prefer not to.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try

Code:
Dim LastRating As Long, c As Range
LastRating = Cells(Cells.Rows.Count, "A").End(xlUp).Row

For Each c In Range("F4:F" & LastRating).SpecialCells(xlCellTypeFormulas)
    If c.Value <> "" Then
        c.Borders(xlEdgeLeft).LineStyle = xlContinuous
        c.Borders(xlEdgeTop).LineStyle = xlContinuous
        c.Borders(xlEdgeBottom).LineStyle = xlContinuous
        c.Borders(xlEdgeRight).LineStyle = xlContinuous
        c.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End If
Next c
 
Upvote 0
Actually, VoG, that did the opposite of what I needed, so I swapped "<>" for "=" and it works perfectly. Thank you very much!
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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