Creating Borders using a macro

lar48ry

Board Regular
Joined
Feb 4, 2005
Messages
53
Hi all,
I have a macro (see below) that will create borders around a range of cells based on a numerical value entered into Column 'A' . However, I would like it to skip a cell if it contains a 1 (one).

Also I am trying to get it to ignore rows that already have borders assigned, if possible.

Here is the current macro:

Sub MULTIBORDERS2()
' MULTIBORDERS Macro
' Created by Larry A. Patzer
' Creates multiple borders based on a number
' being entered into Column A
'
Dim rng As Range
Dim Cell As Range

On Error GoTo XIT
Set rng = ActiveSheet.Columns("A").Cells
Set rng = rng.SpecialCells(xlCellTypeConstants, xlNumbers)
On Error GoTo 0

For Each Cell In rng.Cells
With Cell.Resize(1, 9)
With .BORDERS(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With .BORDERS(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

With .BORDERS(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .BORDERS(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With

With .BORDERS(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
Next Cell
Exit Sub

XIT:
MsgBox "No numeric values found in column A"

End Sub
 

Some videos you may like

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

lar48ry

Board Regular
Joined
Feb 4, 2005
Messages
53
I figured out how to use this macro as i needed to ignore the first row with a number in it. I just removed the part that installed a border at the top of the selected range. Worked like a charm.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,223
Messages
5,594,908
Members
413,952
Latest member
JGer

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
Top