PC Review


Reply
Thread Tools Rate Thread

assign a name to a cell using vb

 
 
jnewl
Guest
Posts: n/a
 
      14th Oct 2008
what is the code to assign a name to a cell using vb?
thanks
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      14th Oct 2008
Dim myCell as range
set mycell = activesheet.range("x9")
mycell.name = "avalidnamehere"



jnewl wrote:
>
> what is the code to assign a name to a cell using vb?
> thanks


--

Dave Peterson
 
Reply With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      14th Oct 2008
Sub Macro1()
ActiveWorkbook.Names.Add Name:="qwerty", RefersToR1C1:="=Sheet1!R3C2"
End Sub
--
Gary''s Student - gsnu200806


"jnewl" wrote:

> what is the code to assign a name to a cell using vb?
> thanks

 
Reply With Quote
 
Stefi
Guest
Posts: n/a
 
      14th Oct 2008
ActiveWorkbook.Names.Add Name:="nametoassign", RefersTo:="=Sheet1!A1"
assigns name "nametoassign" to cell A1 in Sheet1.

Regards,
Stefi

„jnewl” ezt *rta:

> what is the code to assign a name to a cell using vb?
> thanks

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      14th Oct 2008
vba

range("a1").name="typenamehere"

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"jnewl" <(E-Mail Removed)> wrote in message
news:70EC7881-FE99-4197-A788-(E-Mail Removed)...
> what is the code to assign a name to a cell using vb?
> thanks


 
Reply With Quote
 
jnewl
Guest
Posts: n/a
 
      14th Oct 2008
i have multi tabs on a series of worksheets. i am inserting a column at the
beginning of each worksheet and then populating that column with the name on
the tab. i want to name the column in "a1", fee sched id.

i tried what you suggested but i get an error. 'name not found error"

what am i doing wrong


Sub fixdata()
Dim wks As Worksheet
Dim mycol As Long
Dim lastrow As Long
Dim mycell As Range
mycol = 1
For Each wks In ActiveWorkbook.Worksheets
With wks
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Columns(mycol).Insert
.Range(.Cells(1, mycol), .Cells(lastrow, mycol)).Value = "'" & wks.Name
Set mycell = ActiveSheet.Range("A1")
mycell.Name = "fee sched id"
End With
Next wks
End Sub

thanks



"Dave Peterson" wrote:

> Dim myCell as range
> set mycell = activesheet.range("x9")
> mycell.name = "avalidnamehere"
>
>
>
> jnewl wrote:
> >
> > what is the code to assign a name to a cell using vb?
> > thanks

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      14th Oct 2008
Since you want to use the same name for each worksheet, you'll want to use a
local (or worksheet) level name.

Option Explicit

Sub fixdata()
Dim wks As Worksheet
Dim mycol As Long
Dim lastrow As Long
Dim mycell As Range
mycol = 1
For Each wks In ActiveWorkbook.Worksheets
With wks
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Columns(mycol).Insert
.Range(.Cells(1, mycol), .Cells(lastrow, mycol)).Value = "'" & wks.Name
.Range("A1").Name = "'" & .Name & "'!fee_sched_id"
End With
Next wks
End Sub

I changed your space characters to underscore in the name of the cell.

jnewl wrote:
>
> i have multi tabs on a series of worksheets. i am inserting a column at the
> beginning of each worksheet and then populating that column with the name on
> the tab. i want to name the column in "a1", fee sched id.
>
> i tried what you suggested but i get an error. 'name not found error"
>
> what am i doing wrong
>
> Sub fixdata()
> Dim wks As Worksheet
> Dim mycol As Long
> Dim lastrow As Long
> Dim mycell As Range
> mycol = 1
> For Each wks In ActiveWorkbook.Worksheets
> With wks
> lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
> .Columns(mycol).Insert
> .Range(.Cells(1, mycol), .Cells(lastrow, mycol)).Value = "'" & wks.Name
> Set mycell = ActiveSheet.Range("A1")
> mycell.Name = "fee sched id"
> End With
> Next wks
> End Sub
>
> thanks
>
> "Dave Peterson" wrote:
>
> > Dim myCell as range
> > set mycell = activesheet.range("x9")
> > mycell.name = "avalidnamehere"
> >
> >
> >
> > jnewl wrote:
> > >
> > > what is the code to assign a name to a cell using vb?
> > > thanks

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
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
Assign Color to a Cell based on another Cell on a diff Sheet VROSARIO7 Microsoft Excel Worksheet Functions 1 6th Jul 2009 08:48 PM
assign the formatted cell value (date) to another cell? Lars Uffmann Microsoft Excel Programming 3 18th Aug 2008 10:19 PM
How can I assign a data for one cell from another fixed cell? =?Utf-8?B?bmV3IEV4Y2VsIHVzZXI=?= Microsoft Excel New Users 3 9th Nov 2007 05:46 PM
How do i assign cell A1 to show the current cursor cell in Excel? =?Utf-8?B?T0I=?= Microsoft Excel Misc 2 11th Oct 2006 04:02 PM
How to: assign a value to a cell without selecting the cell first =?Utf-8?B?R2VvcmdlIEZ1cm5lbGw=?= Microsoft Excel Programming 4 23rd Jan 2006 02:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:50 PM.