Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 219
Default Doesn't work with or without parenthesis?

I'm trying to create a formula to increment a counter. The variable name
contains a variable.
sCt = "A"


If rCell = "16" Then
sCt = rCell.Offset(, 2).Value
"l16" & sCt & "ct" = "l16 " & sCt & "ct" + 1
End If

It's turning red on me. I want it to yield

l16ACt = l16ACt + 1

That is "el sixteen Ay cee tee"

Does anyone know how to enter this?

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Doesn't work with or without parenthesis?

VB doesn't support what you are trying to do, at least not in the way you
are trying to do it. You should read up on arrays... they were placed in the
VB language strictly to be able to handle what you are attempting to do.
Basically, arrays are identically named variables that use an index value to
differentiate between the individual members of the array. This seems like a
reasonably decent introduction to arrays for you to study up on them...

http://patorjk.com/programming/tutorials/vbarrays.htm

If you Google "vb arrays tutorial" (without the quote marks), you will get
other links as well.

--
Rick (MVP - Excel)


"salgud" wrote in message
...
I'm trying to create a formula to increment a counter. The variable name
contains a variable.
sCt = "A"


If rCell = "16" Then
sCt = rCell.Offset(, 2).Value
"l16" & sCt & "ct" = "l16 " & sCt & "ct" + 1
End If

It's turning red on me. I want it to yield

l16ACt = l16ACt + 1

That is "el sixteen Ay cee tee"

Does anyone know how to enter this?

Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 219
Default Doesn't work with or without parenthesis?

On Fri, 25 Sep 2009 13:13:27 -0400, Rick Rothstein wrote:

VB doesn't support what you are trying to do, at least not in the way you
are trying to do it. You should read up on arrays... they were placed in the
VB language strictly to be able to handle what you are attempting to do.
Basically, arrays are identically named variables that use an index value to
differentiate between the individual members of the array. This seems like a
reasonably decent introduction to arrays for you to study up on them...

http://patorjk.com/programming/tutorials/vbarrays.htm

If you Google "vb arrays tutorial" (without the quote marks), you will get
other links as well.


Darn! I've been avoiding learning about arrays for some time. Now you're
making me learn. I hate when that happens! :)

Seriously, thanks for the lead. This gives me the incentive to learn about
arrays (again, used them a little bit years ago) and get over the hump. My
situation appears to be a good learning example of how/when to use arrays.

I did find a workaround for my original problem, but it only works if I'm
willing to temporarily abandon my standard variable naming convention
(which I'd prefer not to do). If I change the variables to one character,
like "R", "A", "G" and "B", I can use those in Don's formula to get my
desired counts of those categories. E.g.,

If rCell = "16" Then
sCt = rCell.Offset(, 2).Value
sCt = sCt + 1
End If

Works fine if sCt is the code and the variable name both and is one of R,
A, G or B.

But it would probably do me good to learn arrays, so thanks for the
suggestion. Now I need to go and figure out how to do this with an array...
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
parenthesis puiuluipui Excel Discussion (Misc queries) 2 May 27th 08 01:59 PM
Short key for parenthesis - Hot key Anders Excel Discussion (Misc queries) 0 December 19th 07 09:09 AM
Parenthesis problem gmangrove Charts and Charting in Excel 1 December 21st 06 03:11 AM
WHAT ARE PARENTHESIS IN FORMULAS? ann New Users to Excel 2 August 21st 06 10:43 PM
Parenthesis - to use or not to use? John Coleman Excel Programming 4 September 13th 04 02:33 PM


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