Forum Discussion
VBA Macro to create borders dynamically
Here is sample code for you to experiment with in another worksheet, before you try doing something similar as part of (or called from) your current macro:
Sub SettingBorders()
With Range("B12:C14")
With .Borders(XlBordersIndex.xlEdgeLeft)
.LineStyle = XlLineStyle.xlContinuous
.TintAndShade = 0
.Weight = XlBorderWeight.xlMedium
End With
With .Borders(XlBordersIndex.xlEdgeRight)
.LineStyle = XlLineStyle.xlDouble
.Color = vbRed
.TintAndShade = 0
.Weight = XlBorderWeight.xlThick
End With
End With
End SubThose "XlBordersIndex.", "XlLineStyle.", and "XlBorderWeight." qualifiers are not required, but they are useful with the VBA editor's Intellisense feature. (Each of those qualifier names is an enumeration -- a set of numbers that have names and a related meaning.) To try the other options (enumeration members) available: Delete the name that follows the period, and delete the period also. Retype the period, and you will see a dropdown list of the valid options (the other enumerations); click one to select it (or first type a few characters if you want to scroll to a different part of the list). Rerun the procedure.