Resizing a named range to include titles

davidb50

Board Regular
Joined
Apr 25, 2014
Messages
99
Hi
I'm using Excel 2003. I have a dataset that covers range("A1:H87") and a dynamic named range for each column that excludes titles e.g. NamedRangeColumnA = range("A2:A87").

Within VBA, I need to be able to resize NamedRangeColumnA to include the title e.g. it becomes range("A1:A87"). I've come up with a solution below which works (with help from the MVPs on this site).

However, I was wondering if there is a simpler way to achieve this (perhaps using offset)?

Code:
Sub Learning_020()

    Dim MyRange As Range
    Dim intFirstRow As Integer
    Dim intFirstCol As Integer
    Dim intLastRow As Integer
    Dim MyResizedRange As Range
    
    Set MyRange = Range("NamedRangeColumnA")
    
    With MyRange
        intFirstRow = .Row
        intFirstCol = .Column
        intLastRow = intFirstRow + .Rows.Count - 1
    End With


    Set MyResizedRange = Range(Cells(intFirstRow - 1, intFirstCol), Cells(intLastRow, intFirstCol))
    
    MyResizedRange.Select
    
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi
I'm using Excel 2003. I have a dataset that covers range("A1:H87") and a dynamic named range for each column that excludes titles e.g. NamedRangeColumnA = range("A2:A87").

Within VBA, I need to be able to resize NamedRangeColumnA to include the title e.g. it becomes range("A1:A87"). I've come up with a solution below which works (with help from the MVPs on this site).

However, I was wondering if there is a simpler way to achieve this (perhaps using offset)?
Maybe:
Code:
Sub Learning_020()
    Dim MyRange As Range
    Dim MyResizedRange As Range
    
    Set MyRange = Range("NamedRangeColumnA")
    Set MyResizedRange = MyRange.Offset(-1, 0).Resize(MyRange.Rows.Count + 1)
    MyResizedRange.Select
End Sub
 
Upvote 0
Another way...
Code:
Sub Learning_020a()
    Dim MyResizedRange As Range
    Set MyResizedRange = Range("NamedRangeColumnA").Offset(-1).Resize(Range("NamedRangeColumnA").Rows.Count + 1)
    MyResizedRange.Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,422
Messages
6,119,396
Members
448,891
Latest member
tpierce

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