Create a Named Range in Excel with VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello Group:
I am attempting to create a named range in Excel by using a VBA macro. I
have a table of information where the number of rows is variable. I need to
create a hard coded range name by running a macro which will change as the
number of rows changes.

I attempted to record keystrokes, but am not getting the correct result.
Does anyone have any code they could share in this case?
thx
Bill
 
If your table already has a range name (in my example "mytable"), then try
this piece of code

range("mytable").currentregion.name="mytable"

If the range doesn't exist yet, you need to add statements to set the active
cell to one within the range of interest, then continue with this code:

activecell.currentregion.name="mytable"

Substitue your named range as needed.

Rick Ward
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top