+ Reply to Thread
Results 1 to 4 of 4

Case issues in VBA

  1. #1
    Registered User
    Join Date
    04-18-2006
    Posts
    34

    Case issues in VBA

    Hello ladies and gentlemen. I have a rather frustrating issue that dates a few months back, so I hope to solve it today.

    The following code tests a value in Column A. If the value is between 1-5 or equal to 11, column B will return the string A. It works.
    Please Login or Register  to view this content.
    And I believe the equivalent (replacing If with Select Case) goes:
    Please Login or Register  to view this content.
    However, if I run the second code with matching values in Column A (11, 1, 3, etc), nothing happens. Well, maybe something happens, but the values in Column B remain blank.

    Could anybody tell me why?
    Last edited by ArenaNinja; 10-12-2008 at 06:03 PM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    Case comparisons will be 1 of 3 conditions: True, False or something else. Change your Select Case to:
    Please Login or Register  to view this content.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello ArenaNinja,

    Here is your code with the Select Case statement equivalent. Select Case only "Or"s conditions, so you have to rewrite you conditional test from inclusive (>0 And <=5) to exclusive (<0 Or >5) for it to work.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    04-18-2006
    Posts
    34
    Thanks for the replies guys.

    Ross,

    your idea makes sense, except that I really need to make these inclusive. I'm writing this for a friend (who can't show me his data) and he tells me he's got about 20 conditions he needs for letters A-G.

    KH:

    Looks like that worked! I think I can see in my head why now. Generally, select Cases are numbers, so you'll do case 1, case 2, case n. In this case, I was selecting to test a field value, and screwed up somewhere (still not sure where..).

    Final code:
    Please Login or Register  to view this content.
    Sure, it's pretty badly written, but it'll do the job :D

    Thanks guys!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Spellnumber
    By Williams in forum Excel - New Users/Basics
    Replies: 13
    Last Post: 02-16-2020, 03:34 AM
  2. number to words
    By vjn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2008, 04:57 AM
  3. Numbers to Text
    By sachinattri in forum Excel General
    Replies: 6
    Last Post: 06-15-2008, 03:07 AM
  4. "Translating" numbers into words
    By Portuga in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2008, 11:44 AM
  5. Spell number
    By nowfal in forum Excel General
    Replies: 4
    Last Post: 08-20-2007, 04:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1