Using VB to to create named ranges
Hi,
This is a two part question that may have one answer.
1. I'm using the following code to create a named range of **everything** on
a worksheet:
Sub CreateRangeName()
Dim first_row As Integer
Dim first_col As Integer
Dim num_rows As Integer
Dim num_cols As Integer
Dim rng As String
With ActiveSheet
first_row = .UsedRange.Row
first_col = .UsedRange.Column
num_rows = .UsedRange.Rows.Count
num_cols = .UsedRange.Columns.Count
End With
rng = "R" & first_row & "C" & first_col & ":R" & num_rows & "C" & num_cols
ActiveWorkbook.Names.Add Name:="RangeName", RefersToR1C1:="=" & rng
End Sub
This works fine on a worksheet where I want to select everything but there
maybe occasion where I want to **leave out a section** from the range. Is
there a better way I could code this so I can be more specific about the
range I want to name but without hardcoding cell addresses.
Thanks
|