Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default assign a name to a cell using vb

what is the code to assign a name to a cell using vb?
thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default assign a name to a cell using vb

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default assign a name to a cell using vb

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default assign a name to a cell using vb

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default assign a name to a cell using vb

vba

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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"jnewl" wrote in message
...
what is the code to assign a name to a cell using vb?
thanks




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default assign a name to a cell using vb

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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default assign a name to a cell using vb

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign Color to a Cell based on another Cell on a diff Sheet VROSARIO7 Excel Worksheet Functions 2 July 6th 09 08:53 PM
assign a value to a cell totally lost New Users to Excel 8 February 9th 09 05:01 PM
assign the formatted cell value (date) to another cell? Lars Uffmann Excel Programming 3 August 18th 08 10:19 PM
How can I assign a data for one cell from another fixed cell? new Excel user New Users to Excel 3 November 9th 07 05:46 PM
How do i assign cell A1 to show the current cursor cell in Excel? OB Excel Discussion (Misc queries) 2 October 11th 06 04:02 PM


All times are GMT +1. The time now is 04:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"