PC Review


Reply
Thread Tools Rate Thread

Add Cell name

 
 
KentAE
Guest
Posts: n/a
 
      8th Jan 2009
Hi Guys, I'm trying to give active cell a name but it doesn't work. Please
help me!

Sub CellName()
Dim myFile, myKlas, myDiv, myName, rc, ref As String

myFile = ActiveSheet.Name ' it's "D35" for example
myKlas = myFile
myDiv = ActiveCell.Value ' it's "South" for example

myName = myKlas & myDiv ' the name I want to give the cell

Row = ActiveCell.Row
Col = ActiveCell.Column
rc = "R" & Row & "C" & Col

ref = myFile & "!" & rc
ActiveWorkbook.Names.Add Name:=myName, RefersTo:="=" & ref & " """
End Sub
--
If you are old enough, you have your future behind you.
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      8th Jan 2009
Sub CellName()
Dim myFile, myKlas, myDiv, myName, rc, ref As String
Dim nRow As Long, Col As Long

myFile = ActiveSheet.Name ' it's "D35" for example
myKlas = myFile
myDiv = ActiveCell.Value ' it's "South" for example

myName = myKlas & myDiv ' the name I want to give the cell

nRow = ActiveCell.Row
Col = ActiveCell.Column
rc = "R" & nRow & "C" & Col

ref = myFile & "!" & rc
ActiveWorkbook.Names.Add Name:=myName, RefersTo:="=" & ref
End Sub


BTW, all of those variables are not of type string, you need to declare each
explicitly, like tis

Dim myFile As String, myKlas As String, myDiv As String, myName As String,
rc As String, ref As String

and you should not use Row as a variable name, it is a VBA keyword.


--
__________________________________
HTH

Bob

"KentAE" <(E-Mail Removed)> wrote in message
news:EA73A523-E4EE-4D0E-8D12-(E-Mail Removed)...
> Hi Guys, I'm trying to give active cell a name but it doesn't work. Please
> help me!
>
> Sub CellName()
> Dim myFile, myKlas, myDiv, myName, rc, ref As String
>
> myFile = ActiveSheet.Name ' it's "D35" for example
> myKlas = myFile
> myDiv = ActiveCell.Value ' it's "South" for example
>
> myName = myKlas & myDiv ' the name I want to give the cell
>
> Row = ActiveCell.Row
> Col = ActiveCell.Column
> rc = "R" & Row & "C" & Col
>
> ref = myFile & "!" & rc
> ActiveWorkbook.Names.Add Name:=myName, RefersTo:="=" & ref & " """
> End Sub
> --
> If you are old enough, you have your future behind you.



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to copy the formulae of one cell to all the cell in the rangewith the specific cell and columnnumber changing Options Yuvraj Microsoft Excel Misc 0 29th Jun 2009 11:20 AM
Populate a cell if values in cell 1 and cell 2 match cell 3 and 4 tviola@wi.rr.com Microsoft Excel Programming 1 21st Aug 2008 10:13 PM
Populate a cell if values in cell 1 and cell 2 match cell 3 and 4 tviola@wi.rr.com Microsoft Excel Worksheet Functions 0 21st Aug 2008 08:44 PM
NEED VBA TO SELECT A CELL; NOTE THE CELL VALUE;COPYADJ CELL;FIND CELL VALUE IN A RANGE AND SO ON CAPTGNVR Microsoft Excel Programming 2 8th Jul 2007 04:18 PM
How to create/run "cell A equals Cell B put Cell C info in Cell D =?Utf-8?B?YWJtYjE2MQ==?= Microsoft Excel Misc 5 26th Jan 2006 06:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:32 PM.