General VBA question

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
624
Office Version
  1. 2016
Platform
  1. Windows
Is there a way to specify Cells, columns, or rows in vba were if you had to insert a column or row it will not required change the reference to the new Cells, columns, or rows in VBA. So VBA to automatically refer to the new Cells, Columns or Row reference. Have VBA function like formulas

not sure if that is clear. feel free to ask me question to better explain.

Thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Let’s say in VBA I have

range(“B3”).value

in later I insert a column in front of column B so the value in B3 is now in C3 is there another way to reference
range(“B3”).value in VBA where I did not have to go back to VBA to change it to C3

its easy to remember just to go back change C3 but if you have multiple reference in VBA that is effected by that one insert.
 
Upvote 0
You can use named ranges.

For example, let's name Range("B3") "MyRange".
Then, we can see its value in a message box like this:
VBA Code:
Sub Test()
    MsgBox Range("MyRange").Value
    MsgBox Range("MyRange").Address
End Sub
The first message box returns the value. The second returns the address.

As you insert row/columns, you will see that it is still connected to that cell. So the address of "MyRange" will change, and the value stays the same.
 
Upvote 0
Solution
Thanks Joe Never thought or knew I could use name range in VBA. That will definitely do the trick.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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