Resize all named ranges in a workbook using VBA (add columns)

farrukhikram

New Member
Joined
Aug 9, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hello guys,

I have hundreds of named ranges in each excel file and I have hundreds of excel files to deal with (all with different named ranges). I am looking for a VBA which (without a specific pattern), resizes ALL the named ranges and just add 12 columns to each range. (All the ranges contain only a single row), only horizontal expansion is required.

I found another thread here in the same forum, following is a link the that thread as well:

Click here to see the other thread

Note: I am a beginner / NOVOICE in VBA programming so a detailed help will be appreciated (like where to paste the macro as well).
 
Last edited by a moderator:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I think the other thread got deleted (the link above is not working anymore), so I am pasting my question from the other thread here as well:

Hello Guys,

After a lot of research on internet, at last I got to this question which is exactly what I am trying to do. Just to explain the issue further in following steps:

1. I pasted the following code from above in 'ThisWorkbook' tab VBA editor:

VBA Code:
Sub AdjNamedRanges_New()
Dim nRange As Name
Dim strName As String
Dim ans As Long
For Each nRange In ActiveWorkbook.Names
strName = nRange.Name
With ActiveWorkbook.Names.Item(strName)
ans = Range(strName).Columns.Count

.RefersTo = .RefersToRange.Resize(, ans + 12)

End With
Next nRange
End Sub

2. When I ran this Macro, it gave me error '400'

3. When I press 'F8', both 'nRange' and 'strName' are showing 'File Name' (The current file name) on mouse over.

4. After the 'For' statement, The strName on mouse shows the error "<Object variable or with block variable not set>

5. I have tried by pasting the above code in a new module as well as in the active sheet as well, but in vain.

Can you please tell me what I am doing wrong?
 
Upvote 0

Forum statistics

Threads
1,223,713
Messages
6,174,038
Members
452,542
Latest member
Bricklin

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