How to use macro to create a name

rickyckc

Active Member
Joined
Apr 1, 2004
Messages
327
Hi all,

I have a workbook call Sales.xls

In this workbook, there is a sheet call Sales Staff. In column C, there is a sales person name list. In C2, I want it to be blank. From C3 down-wards, are names of sales person. This name list are varied all the time, i.e. could be 10 people (C2:C12), could be 23 people (C2:25), etc. How to use macro to create a name for this (un-fixed) list ?

Currently, what I have is this, which is done by manually selection...

ActiveWorkbook.Names.Add Name:="SalesStaff", RefersToR1C1:= "='Sales Staff'!R2C3:R7C3"

Please help. Thanks.

Best Regards,
Ricky
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
For a simple solution try:

Range("c3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.name = "SalesStaff"

This ignores c2 which you want blank and just names the list of staff names.
Each time this code runs, the full list is named irrespective of the number of entries.
Note that the list works down to the first blank, so there cannot be gaps in the list.
 
Upvote 0
No need to Select:

Code:
Sub test()
Range("C3:C" & Range("C3").End(xlDown).Row).Name = "SalesStaff"
End Sub
 
Upvote 0

Forum statistics

Threads
1,222,405
Messages
6,165,864
Members
451,988
Latest member
boo203

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