Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default VBA Names madness

Every time I think I've got the concepts and syntax for Names in VBA
straight I discover
something I don't know how to do. The current problem is exemplified below:

Private Sub TheButton_Click()
Dim nIn As Integer, nOut As Integer

nIn = [mixer1!nInputs] ' This works... nIn is 6

Dim str As String
str = ActiveSheet.name & "nInputs" ' this forms "mixer1!nInputs"
nIn = [str] ' Fails, obviously because str is a string.

MsgBox (nIn)

End Sub

nInputs has been defined as a Name local to Worksheet mixer1, and the cell
which it RefersTo has the
integer 6 in it. Thus [mixer1!nInputs] gives, as it should, 6. However, I
want to generalize this
so as to pick up the nInputs value from the ActiveSheet, as opposed to
hard-wiring a particular
sheet name.

The (obviously lame) attempt builds "mixer1!nInputs", but since it is a
String there is a type mismatch for
the Evaluation operator [expression]. Now, I can understand that, as I do
understand the difference
between xxx and "xxx". What I can't come up with is the proper syntax for
what I want to do.

Help!

TIA

Ed



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA Names madness

I think the context you are looking for is:

"mixer1!" & nInputs

Allan Koodray
-----Original Message-----
Every time I think I've got the concepts and syntax for

Names in VBA
straight I discover
something I don't know how to do. The current problem is

exemplified below:

Private Sub TheButton_Click()
Dim nIn As Integer, nOut As Integer

nIn = [mixer1!nInputs] ' This works... nIn is 6

Dim str As String
str = ActiveSheet.name & "nInputs" ' this

forms "mixer1!nInputs"
nIn = [str] ' Fails, obviously because str is a

string.

MsgBox (nIn)

End Sub

nInputs has been defined as a Name local to Worksheet

mixer1, and the cell
which it RefersTo has the
integer 6 in it. Thus [mixer1!nInputs] gives, as it

should, 6. However, I
want to generalize this
so as to pick up the nInputs value from the ActiveSheet,

as opposed to
hard-wiring a particular
sheet name.

The (obviously lame) attempt builds "mixer1!nInputs", but

since it is a
String there is a type mismatch for
the Evaluation operator [expression]. Now, I can

understand that, as I do
understand the difference
between xxx and "xxx". What I can't come up with is the

proper syntax for
what I want to do.

Help!

TIA

Ed



.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default VBA Names madness

the square brackets are short for evaluate.

This seemed to work ok for me:

str = ActiveSheet.Name & "!nInputs" ' this forms "mixer1!nInputs"
nIn = Application.Evaluate(str)
MsgBox nIn





Jag Man wrote:

Every time I think I've got the concepts and syntax for Names in VBA
straight I discover
something I don't know how to do. The current problem is exemplified below:

Private Sub TheButton_Click()
Dim nIn As Integer, nOut As Integer

nIn = [mixer1!nInputs] ' This works... nIn is 6

Dim str As String
str = ActiveSheet.name & "nInputs" ' this forms "mixer1!nInputs"
nIn = [str] ' Fails, obviously because str is a string.

MsgBox (nIn)

End Sub

nInputs has been defined as a Name local to Worksheet mixer1, and the cell
which it RefersTo has the
integer 6 in it. Thus [mixer1!nInputs] gives, as it should, 6. However, I
want to generalize this
so as to pick up the nInputs value from the ActiveSheet, as opposed to
hard-wiring a particular
sheet name.

The (obviously lame) attempt builds "mixer1!nInputs", but since it is a
String there is a type mismatch for
the Evaluation operator [expression]. Now, I can understand that, as I do
understand the difference
between xxx and "xxx". What I can't come up with is the proper syntax for
what I want to do.

Help!

TIA

Ed


--

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
Sorting Madness JSnow Excel Discussion (Misc queries) 5 February 11th 09 05:52 PM
March Madness and Conditional Formatting (Excel2007) Denniso6 Excel Discussion (Misc queries) 0 March 12th 07 03:50 PM
Formula Madness IoHeFy Excel Discussion (Misc queries) 2 January 4th 07 01:16 PM
Multimodal Madness Rothman Excel Worksheet Functions 0 March 16th 06 12:56 AM
More Macro Madness Josh in Tampa Excel Programming 5 October 24th 03 11:14 PM


All times are GMT +1. The time now is 10:35 PM.

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"