Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Refer to a Name saved prior my macro Starts from VBA excel

Hi!

1)
If I have a name, saved prior a start my macro eg:

MyArray=("Bush","Mitterrand", "Blair")

how can I refer to Myarray(1) from VBA to get the following answer:

MyArray(1)=Miterrand

2)
1)
how can I refer to the value of Screen_Number from VBA.
at the moment I am using this code:

SUB aa()
dim Y
Y=Names("Screen_Number").Value
Y = Mid(Y, 2, 10)
MSGBOX Y
END SUB
"This works but I suppose there is another better way"



Many Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Refer to a Name saved prior my macro Starts from VBA excel

'-------------------------------------
Option Base 1 ' top of module otherwise array starts at zero
Sub test()
Dim MyArray As Variant
MyArray = Array("Bush", "Mitterrand", "Blair")
MsgBox (MyArray(1))
End Sub
'----------------------------------


Names refer to *Ranges* and can be at WorkBook or WorkSheet level. Thi
can be programmed, but, if done manually, Excel makes the firs
instance at WB level and subsequent use of the same name at shee
level.

Even though your code works, it is more correct to refer to a range, s
this works:-
Y = Mid(Range("Screen_Number").Value, 2, 10)

This is, however, bad (lazy) programming because it automaticall
refers to the ActiveSheet which may not be the one you want (o
requires code to make it active), or will crash if the ActiveSheet doe
not contain the name.

You might get away with this in small amounts of code, but once yo
start using more than one workbook/worksheet it is really necessary t
fully qualify your name accordingly :-

y
Workbooks("Book1.xls").Worksheets("Sheet1").Range( "Screen_Number").Value

This saves all sorts of seemingly "strange" results as the applicatio
grows in size. Interestingly, because of this qualification, VB enable
us to define macro names the same as worksheet etc. names so we can us
:-
'-----------------------------------
Sub test()
Dim Screen_Number As Range
Set Screen_Number = Worksheets("Sheet1").Range("Screen_Number")
MsgBox (Screen_Number.Value) ' no quotes round name
End Sub
'----------------------------------

Hope this helps

--
Message posted from http://www.ExcelForum.com

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
How do I recover a prior version of a saved document? trpnfly Excel Discussion (Misc queries) 1 April 4th 10 03:43 AM
Excel E-2007 starts, but Installer also starts 3 times??? Thanks for the Great Tip Setting up and Configuration of Excel 0 January 24th 10 03:21 AM
How do I run a macro upon saving a file but prior to actual save? Hawk186 Excel Discussion (Misc queries) 2 June 6th 08 09:38 PM
How to remove macro saved on excel folder Jurassien Excel Discussion (Misc queries) 5 February 20th 07 07:39 PM
Excel Starts up w/a Personal Macro page Parker Excel Discussion (Misc queries) 4 August 29th 05 09:31 PM


All times are GMT +1. The time now is 06:50 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"