can i use named ranges instead of ranges in vba

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,195
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
I everyone,

i have an ongoing problem with writing macros only for someone to come along and say something like
"can we have 10 dropdowns instead of 8 in sheet "Data"?
and as you can imagine that normally involves inserting two rows but of course my macros still all look at the old columns and rows and i'm sure we have all done it before you now have to go through every macro editing it to the changed ranges.

so I have a big project coming up and iknow this is going to be a problem, so if anyone know how toeasily sole this please let me know any tipes will be helpfull, but also i thought if i used named ranges for everything instead of a range it would move as the sheet moves so as an example here is atypicale macro i will be using ow could i change the range to name range "Testit1"?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("E61:H70")) Is Nothing Then

If Target.Value = "" Or Target.Value = "Select" Then

Target.RowHeight = 15

Range("E61:H70").Locked = False

Exit Sub
end if
end if
end sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
A named range is entered the same way as a range in vba. Range("name of range")
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,975
Members
449,200
Latest member
Jamil ahmed

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