Can Macro Recorder pick up Defined Names?

smiley3141

Board Regular
Joined
Aug 13, 2010
Messages
77
I recorded a Macro and it functions properly. The problem is that I had given a name to every range that the Macro performs an action on, but the Macro recorder still referred to ranges by their Cell names (for example "D5:D8"). Is there some way to make the Macro Recorder use the Defined Names instead of having to go in and change them all, or do I need to change them manually?

I appreciate any help you have for me.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
When you record the macro, instead of clicking on the cells, select from the menu Edit\ Goto\ Your_Named_Range. Then your named range will be recorded in your macro.

Or you can select Your_Named_Range from the name drop-down list to the left of the formula bar.
 
Upvote 0
Thank you AlphaFrog, for your help. Once I have done that, how do I perform an action on the Goto Reference?

On my spreadsheet page Column J is named "Database_Comments". When I used the drop down list to select this name and then tried to autofit the column width, the macro recorder came up with the following:

Application.Goto Reference:="Database_Comments"
Columns("J:J").EntireColumn.AutoFit

How can I get the autofit to work without reference to "J:J"? I have tried putting "Database_Comments" in the second line above but have not been able to make that work.
 
Upvote 0
Code:
Range("Database_Comments").EntireColumn.AutoFit
 
Upvote 0
Thanks. That is what I tried at first when I entered the Range names for all the cell selections I did but did not have any luck.

It seems to be working now. Must have mistyped it before. Thank you for your help.

Now that the problem is solved, do you know how I could activate (or select) the go to reference, so I do not have to go back and type in the names later?
 
Upvote 0
Now that the problem is solved, do you know how I could activate (or select) the go to reference, so I do not have to go back and type in the names later?

Maybe I miss something here, but is that so much of a problem?

In fact, the macro recorder is there to help you, not to "write" code. You being the developer/programmer - write the code.

You can for instance copy my line of code and paste it a number of times. Then, replace the named range with something else. The macro will continue to work :)
 
Upvote 0
You are right Wigi. I am the programmer, and the Recorder is there to help, not to write the code. It is not too difficult to manually enter the names. I was asking because I want to improve efficiency (kind of like learning keyboard shortcuts) and thought there might be a way to do this simple task automatically. If there is not, that is fine. If there is, however, I don't want to waste all the time manually inputting names.
 
Upvote 0
You are right Wigi. I am the programmer, and the Recorder is there to help, not to write the code. It is not too difficult to manually enter the names. I was asking because I want to improve efficiency (kind of like learning keyboard shortcuts) and thought there might be a way to do this simple task automatically. If there is not, that is fine. If there is, however, I don't want to waste all the time manually inputting names.

Run this maco, look in the Immediate window (press Ctrl-G) and then the shortcuts Ctrl-C and Ctrl-V will be the only ones needed...

Code:
Sub tst()
For Each nm In ThisWorkbook.Names
    Debug.Print "Range(""" & nm.Name & """).EntireColumn.AutoFit"
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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