Thread: naming cells
View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
John John is offline
external usenet poster
 
Posts: 48
Default naming cells

I am a beginner so I'm still confused about this. I want to create a
variable (I think) called SS# which stands for worksheets(4).cells(2,3)
or whatever. Anytime I use that variable in vb code in excel, vb & excel
treats it like cells(2,3). So I can code things like ss# =
worksheets(n).cells(3,4) and cells(2,3) will change accordingly. Also
the opposite: Cells(9,11) = ss# will put the current value of cells(2,3)
into cells(9,10)

It look like, in your example below, I can do this with:
ssNum = Range("B3") and then use ssNum instead of cells(a3). I haven't
tried it yet.

This isn't a huge deal. It just saves typing alot and makes the code a
lot more readable.

Thanks

John

Steve wrote:
John

Just assign it to a variable in your code. This should give you an idea

Sub test()

For Each sh In Worksheets
ssNum = sh.Range("A3")
'your code goes here
'Anywhere you want to reference the ss number
' in your code juse us ssNum per the msgbox example below
MsgBox "The ss number in sheet " & sh.Name & " is " & ssNum ' for your
test purpose.
Next sh
End Sub


"John" wrote in message
...

Thanks, I forgot to mention I am in vb in excel.
As I page through worksheets, the social security number is always in cell
a,3. It would be cool if I could just refer to SS or Social, or something
like that rather than cells(a,3).

John

Steve wrote:


Basic method of naming a range:
1) Click on A10
2) Click in the name box (just to the left of the formula bar above A1)
3) type Social

Edit or delete the named range:
You can edit your named range using
Insert, Name, Define

Use a name to hold a constant
If you have a constant value, you can:
1) Insert, Name Define to create a name
2) Place the value of the constant in in the 'refers to' area.
Example: if the value of 'Social' is always '3', create the name
'Social' then type '=3' over the top of whatever range is current shown
in the 'refers to' area. This way, your user can't accidentally overwrite
the value.
To refer to the value in a cell simply write '= Social'.







"John" wrote in message
...


How do you name a cell so you can use it in a formula?

I want, say, a,10 to be "Social" or something. Is this possible?

thanks

john