G
Guest
Hi All
When writing excel formulas I use defined ranges that are named (eg
"Schedule") instead of stipulating the range (eg "$AC$22:$DO$100").
How do I use defined names instead of actual ranges when writing code?
I need this because the range on the excel spreadsheet keeps changing when
users insert/delete rows/columns/cells and the range needs to move with the
changes.
Here is an example of code where the ranges would need to be replaced with
the defined name...
Sub Example()
Sheet("Sheet2").Select
Range("AC22O100").Select 'This is called "Schedule"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.NumberFormat = "#,##0.00"
With Selection.Font
.Name = "Tahoma"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Sheet("Sheet1").Select
Range("A13Y100").Select
Selection.Replace What:="0", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
When writing excel formulas I use defined ranges that are named (eg
"Schedule") instead of stipulating the range (eg "$AC$22:$DO$100").
How do I use defined names instead of actual ranges when writing code?
I need this because the range on the excel spreadsheet keeps changing when
users insert/delete rows/columns/cells and the range needs to move with the
changes.
Here is an example of code where the ranges would need to be replaced with
the defined name...
Sub Example()
Sheet("Sheet2").Select
Range("AC22O100").Select 'This is called "Schedule"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.NumberFormat = "#,##0.00"
With Selection.Font
.Name = "Tahoma"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Sheet("Sheet1").Select
Range("A13Y100").Select
Selection.Replace What:="0", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False