Borders for columns macro

aa2000

Board Regular
Joined
Aug 3, 2011
Messages
87
Hello again folks

Im working on a large comparison spreadsheet, hence the questions all of a sudden.
Now I am trying to write a macro to draw a border on the right edge of the furthest cell that contains a value in the whole sheet.
Essentially I am trying to get the macro to look from column IV to A and the moment a value is detected in a column, it stops and puts a border on the right hand edge of the column. (Am I making sense??)

Can anyone help?

Thank you!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
This checks row 1, but you can adapt to your needs:

Code:
Dim iCTR As Integer
 
    For iCTR = 256 To 1 Step -1
        If Len(Sheet1.Cells(1, iCTR).Value) > 0 Then
            Sheet1.Cells(1, iCTR).Select
            With Selection.Borders(xlEdgeRight)
                .LineStyle = xlContinuous
                .ColorIndex = 0
                .TintAndShade = 0
                .Weight = xlThin
            End With
            Exit Sub
        End If
    Next iCTR
 
Upvote 0
Try this:
Code:
Option Explicit

Sub BorderRight()
Dim LastCol As Long

    LastCol = Cells.Find("*", Cells(Rows.Count, Columns.Count), _
        SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column

    Columns(LastCol).Borders(xlEdgeRight).Weight = xlMedium

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,314
Messages
6,159,188
Members
451,544
Latest member
MrsGrayMarlin

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