LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Build Select Case Programmatically

Ronald Dodge gave me this in his answer to my warlier question about InList():

Select Case rngCell.Value
Case "PEN-Pensionable Earnings","Pen2-Pension Plan Charlotte Hyl
HN2","TSP-Textron Savings Plan"

Which I did, and it works perfectly for my purposes -- in fact, back in my
VFP environment I was a big fan of Case statements. However my need here is
to build the case expression programmatically, because on various passes
through a large For..Next Loop, the contents of the needed selection will
vary based on what is found on the current WS.

Here's what I've been doing:

For Each rngWorkCell In Range("K" & lngFoundRow, "K" & lngFoundRow +
lngCount)
For intI = LBound(blnCodes) To UBound(blnCodes) 'Step through the Codes
If blnCodes(intI) Then 'If it's still True, then we need to add it to
the search list
If Left(rngWorkCell, 3) = strCodes(intI) Then 'Matches the Code, Add
it to the list
If Len(strSearchList) = 0 Then 'Have to create a "legal" list
strSearchList = strSearchList + strCodes(intI) 'First one
Else
strSearchList = strSearchList + ", " + strCodes(intI) '..all others
need the comma separator
End If
blnCodes(intI) = False 'Turn off the flag so we don't use this guy
again on the Sheet
End If
End If
Next intI 'Get another Code

...prior to firing off

Select Case Left(rngSubCountCell.Value, 3)
Case strSearchList

Now, by running a creful Debug, I have learned that the case expression
looks like:

Case "PN2, OT-, REG"

...which, of course, guarantees the Case will never be found.

How can I build that list into a variable so that it delivers this:

Case "PN2", "OT-", "REG"

???
--
Dave
Temping with Staffmark
in Rock Hill, SC
 
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
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
Programmatically Select Tab on Ribbon? [email protected] Excel Programming 1 February 21st 07 01:59 PM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM


All times are GMT +1. The time now is 08:37 AM.

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"