Using VBA to name ranges

snipescc

Board Regular
Joined
Aug 29, 2010
Messages
130
Hi folks. I'm trying to use VBA to name ranges, because I will have a lot of them to do (one for each client). If doing this so on a time sheet, an employee can pick the client from a drop down menu, and the next drop-down menu will give codes unique to that client. I'm using Indirect and named ranges to accomplish that. The trouble I'm running into is writing VBA code that will help me make the ranges, since there may be a couple hundred of them and I don't want to do them manually. This is what the document looks like.
SmithJones
96100
97101
98102
99103

<tbody>
</tbody>

I recorded a macro with relative references, that took cell A1 (Smith), copied it, highlighted A2:A5, and then copied the 'Smith' into the place to name ranges. After that, I clicked on B2 (Jones). Here is my code:

Sub Ranges()'
' Ranges Macro
'
' Keyboard Shortcut: Ctrl+q
'
Selection.Copy
ActiveCell.Offset(1, 0).Range("A1:A4").Select
Application.Goto Reference:="Smith"
ActiveCell.Offset(-1, 1).Range("A1").Select
End Sub

What I would like is for the code to do is copy a cell's content, then highlight the 4 cells under it, and name them whatever is in the top cell. When it has done that, I'd like it to go to the top cell of the next column. Can anyone help me? thanks.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Thanks!
It mimics the Create From Selection button in the FORMULA tab which can be quite handy at times :)
 
Upvote 0
Is that the only code i use, and if not, which line do I replace with it? (I'm still pretty new to VBA programming)
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,249
Members
449,075
Latest member
staticfluids

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