Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Access Cell name in VBA code


In an Excel worksheet I define a cell name as Angle_L. How do I access
the value of the cell with the name Angle_L in VBA code?

In a worksheet I have defined a cell with the name Angle_L and put the
value 10 into it.

I run this code in a VBA macro

Range("F2").Select
ActiveCell.Value = Angle_L

But the cell F2 is filled with the value 0, not the value contained in
the cell named Angle_L.

How can I get this to work?


--
ChrisSroka
------------------------------------------------------------------------
ChrisSroka's Profile: http://www.excelforum.com/member.php...o&userid=29168
View this thread: http://www.excelforum.com/showthread...hreadid=488965

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Access Cell name in VBA code

Try:

Range("F2").value = range("Angle_L").value

Hope this helps
Rowan

ChrisSroka wrote:
In an Excel worksheet I define a cell name as Angle_L. How do I access
the value of the cell with the name Angle_L in VBA code?

In a worksheet I have defined a cell with the name Angle_L and put the
value 10 into it.

I run this code in a VBA macro

Range("F2").Select
ActiveCell.Value = Angle_L

But the cell F2 is filled with the value 0, not the value contained in
the cell named Angle_L.

How can I get this to work?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Access Cell name in VBA code

Const cANGEL_L As String = "Angle_L"
Sub demo()
Dim rAngleL As Range
Set rAngleL = Names.Item(cANGEL_L).RefersToRange

' to save a value to the cell
rAngleL.Value = 17
' to save a formula in the cell
rAngleL.FormulaR1C1 = "=R1C1 * 2"
' to read data from the cell
Dim myval As String
myval = rAngleL.Value



End Sub

"ChrisSroka" wrote:


In an Excel worksheet I define a cell name as Angle_L. How do I access
the value of the cell with the name Angle_L in VBA code?

In a worksheet I have defined a cell with the name Angle_L and put the
value 10 into it.

I run this code in a VBA macro

Range("F2").Select
ActiveCell.Value = Angle_L

But the cell F2 is filled with the value 0, not the value contained in
the cell named Angle_L.

How can I get this to work?


--
ChrisSroka
------------------------------------------------------------------------
ChrisSroka's Profile: http://www.excelforum.com/member.php...o&userid=29168
View this thread: http://www.excelforum.com/showthread...hreadid=488965


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Access Cell name in VBA code


Patrick,

I tried the following code (cell F2 contains the number 150):
_________

Const cAngle As String = "Angle_L"

Private Sub CommandButton1_Click()

Dim rAngleL As Range
Set rAngleL = Names.Item("Angle_L").RefersToRange ' **runtime erro
here **

Range("F2").Value = rAngleL.Value

End Sub
___________

It compiled OK, but when I ran it I got a run time error 1004 with th
message "application-defined or object-defined error" when running th
marked line

Any ideas?

Chri

--
ChrisSrok
-----------------------------------------------------------------------
ChrisSroka's Profile: http://www.excelforum.com/member.php...fo&userid=2916
View this thread: http://www.excelforum.com/showthread.php?threadid=48896

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Access Cell name in VBA code


Try dimming rAngleL as an object instead of a range

--
DataCollecto
-----------------------------------------------------------------------
DataCollector's Profile: http://www.hightechtalks.com/m36
View this thread: http://www.hightechtalks.com/t229652



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Access Cell name in VBA code


Tried it, but same error occurs.


--
ChrisSroka
------------------------------------------------------------------------
ChrisSroka's Profile: http://www.excelforum.com/member.php...o&userid=29168
View this thread: http://www.excelforum.com/showthread...hreadid=488965

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Access Cell name in VBA code

Have you definately got a named range Angle_L on your sheet?


ChrisSroka wrote:
Tried it, but same error occurs.


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
Using Access in Excel VB Code Michael Excel Discussion (Misc queries) 1 February 2nd 06 07:31 PM
how to access macro code Patrick Excel Programming 2 November 22nd 04 07:19 PM
Disable Access to VBA Code in XLS File? Richard Fry Excel Programming 1 May 6th 04 02:24 PM
Is there somewhere I can access Excel-VB code at once? Souljah[_3_] Excel Programming 1 April 29th 04 03:46 PM
Where to put code for access by all workbooks David Smith[_2_] Excel Programming 4 February 28th 04 12:25 AM


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

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

About Us

"It's about Microsoft Excel"