resize named range

MetLife

Active Member
Joined
Jul 2, 2012
Messages
334
Office Version
  1. 365
Hi,

I have a named range that is a 25 x 100 table. I am importing data from another csv into this table and the rows will change, so I want to be able to automatically update the named range from

"A1:BB100"

to

"A1:BB250"

if the number of rows increases, is there an easy way to do this in VBA?

Thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,

I have a named range that is a 25 x 100 table. I am importing data from another csv into this table and the rows will change, so I want to be able to automatically update the named range from

"A1:BB100"

to

"A1:BB250"

if the number of rows increases, is there an easy way to do this in VBA?

Thanks
You can adapt this to do what you want.

Code:
Sub ResizeNamedRange()
Dim R As Range
Set R = Range("myRng")  'change name of named range to suit - assumes name is scoped to workbook level
R.Name.RefersTo = Range("A1:BB250")  'set the new range
MsgBox Range("myRng").Address 'verify new range is what is wanted
End Sub
 
Upvote 0
If you want to dynamically find the end of the new range (and let's say we can use column A to do that), then for a named range of "MyRange" on Sheet1, this code would work:
Code:
    Dim lastRow As Long
    Dim nmRng As Name
    
'   Capture named range
    Set nmRng = ActiveWorkbook.Names.Item("MyRange")
    
'   Find last row of data in column A
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Reset range reference of named range
    nmRng.RefersTo = "=Sheet1!$A$1:$B$" & lastRow
 
Upvote 0

Forum statistics

Threads
1,224,755
Messages
6,180,751
Members
452,996
Latest member
nelsonsix66

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