Neeb adjustment to VB code to capture a range.

davidhall80

Well-known Member
Joined
Jul 8, 2006
Messages
663
The code below puts a green border around the cell that is beneath 10 in my chosen range, however I wish to add the border to the row of information instead of just the cell. My columns of data are from columns E to M, but the criteria for whether or not the data gets a green border is in column D....so lets say D15 is less than 10, I would want a border to go around E15:M15. Thanks in advance. Also If there is a better way to write this, please inform me...Thanks again



Sub Test()
For Each c In Range("D2:D350")
If c < 10 Then
c.select
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 4
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 4
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 4
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 4
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End If
Next c
End Sub
 
Code:
Sub Test()
Dim c As Long
Dim Limit As Long
Limit = Cells(Rows.Count, 4).End(xlUp).Row
For c = 2 To Limit
    If Cells(c, 4) < 10 Then
        Range("E" & c).BorderAround xlContinuous, xlThin, 4
    End If
Next c
End Sub
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
david

I'm not talking about using code, I did it manually.

The only issue I can see with what you are trying to do is the changing data.

But anyways I'll go record it, tidy it up and post back.:)
 
Upvote 0
Code:
Sub CF()
Dim rng As Range
Dim LastRow As Long
    
    LastRow = Range("D" & Rows.Count).End(xlUp).Row
        
    Set rng = Range("E2:M" & LastRow)
    
    With rng.FormatConditions
        .Delete
        .Add Type:=xlExpression, Formula1:="=RC4<10"
         With .Item(1).Borders
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 4
        End With
    End With
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,408
Members
449,448
Latest member
Andrew Slatter

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