Help! 2 consecutive columns insert right border vba

jcbv3

New Member
Joined
Mar 19, 2017
Messages
8
I need help guys. Im trying to code a macro whwre in i have about 20 columns and it would check 2 consecutive values below 50 then insert right medium thickness border all the way down. How do i go about this?

Thanks!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
...check 2 consecutive values below 50...

Assuming you mean 2 consecutive values within a particular column, you might consider...

Code:
Sub AddBorders()
Dim LastRow As Long, i As Long
Dim r As Range
For i = 1 To 20 'Change to match your number of columns
    LastRow = Cells(Rows.Count, i).End(xlUp).Row
    For Each r In Range(Cells(1, i), Cells(LastRow, i))
        If r.Value < 50 And r.Offset(1, 0).Value < 50 Then
            With Range(Cells(r.Row, i), Cells(LastRow, i)).Borders(xlEdgeRight)
                .LineStyle = xlContinuous
                .ColorIndex = xlAutomatic
                .Weight = xlMedium
            End With
        End If
    Next r
Next i
End Sub

Cheers,

tonyyy
 
Upvote 0
Thanks man! i have modified it a bit though

Code:
Sub test2()'''version2


Dim LastRow, i As Long
Dim r As Range


For i = 1 To 32
LastRow = Cells(Rows.Count, i).End(xlUp).Row


For Each r In Range(Cells(8, i), Cells(8, i))


        If r.Value < 79.5 And r.Offset(0, 1).Value < 79.5 And r.Offset(0, 2).Value < 79.5 Then
        Range(Cells(r.Offset(2, 0).Row, i + 2), Cells(LastRow, i + 2)).Select
                With Selection
                .Font.FontStyle = "Bold"
                .Font.Color = rgbWhite
                .Interior.Color = rgbRed
                 Call Macro2 
                End With
        End If
        
    Next r


Next i
    
End Sub

What im trying to do now instead of having a border in each interval I just want to have an outside border covering the intervals needed (in this case, the third consecutive instance wherein the value is <79.5 and ends when an interval is > 79.5.

For reference: it should look like the first table instead of the table below it.
the second table is the product of my code now



thanks for all the help guys!
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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