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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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