+ Reply to Thread
Results 1 to 32 of 32

Select Case Statement

Hybrid View

  1. #1
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645
    Why aren't you using quotes for Z4141 etc in the case statements?

  2. #2
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408
    Hi Norie,

    I had quotes around them but that didn't work.

    Gos-C
    Using Excel 2010 & Windows 10
    "It is better to be prepared for an opportunity and not have one than to have an opportunity and not be prepared."

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645
    Does that code even compile?

    For a start there is no such data type as variable which you seem to have here.
    prov As Variable
    Then since you don't have quotes around Z4141 etc then VBA would probably be regarding them as variables.

    And since you have Option Explicit set then VBA should really be flagging that up.

    When you say it doesn't work, how exactly?

  4. #4
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408
    Hi Norie,

    Sorry, I edited my first post to show prov as String. I was changing different things just to see if I can get it to work.

    When I run the code I get Run-time error '1004'. Microsoft Office Excel cannot access the file . . . and I noticed that the file path does not include the "prov" folder, which it should have received from the Select Case Statement.

    Edited . . . I just realized I need to call SelectProvinceCase - the path is now correct, but it still is not working!

    Gos-C
    Last edited by Gos-C; 06-05-2008 at 03:35 PM.

  5. #5
    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 Gos-C,

    Here is how the syntax should be for comparing strings in a Select Case statement.
    Sub SelectProvinceCase()
    
      prov = Left(zName, 5)
        Select Case prov
          Case Is = "Z4141"
            prov = "Nova Scotia Providers"
          Case Is = "Z4242"
            prov = "Quebec Providers"
          Case Is = "Z4343"
            prov = "NFLD Providers"
          Case Is = "Z4444"
            prov = "NEW Brunswick Providers"
          Case Is = "Z4545"
            prov = "PEI Providers"
          Case Is = "Z4646"
            prov = "Ontario Providers"
          Case Is = "Z4747"
            prov = "Saskatchewan Providers"
          Case Is = "Z4848"
            prov = "Saskatchewan Providers"
          Case Is = "Z4949"
            prov = "Alberta Providers"
          Case Is = "Z5050"
            prov = "British Columbia Providers"
          Case Else
            MsgBox "Please verify the z-file name - the provider number appears to be incorrect."
            Exit Sub
       End Select
       
    End Sub
    Sincerely,
    Leith Ross

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960
    You seem to be missing an End If in the commandbutton1_click() sub.
    Ben Van Johnson

  7. #7
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408
    Hi Leith, I have that.

    Hi protonLeah, I also have that.

    (Sorry, the inadvertently omitted them in my post - I had remove them to try to figure out the problem.)

    However, I am still getting the error that MS Excel cannot access the file. The file is saved as a ".csv". I know that the path is correct and it is not being used.

    Any idea for the error?

    Thank you,
    Gos-C

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960
    I seem to recall that spaces are not allowed in http addresses, they use either the underscore or the %20 to separate words. Are you sure your file names are correct? For instance, can you try:

    OSAM%20Z%20FILES, 
    or
    OSAM_Z_FILES
    and elsewhere there are spaces in the filename.

  9. #9
    Registered User
    Join Date
    03-30-2005
    Posts
    7

    Avoid using spaces or underscores

    Avoid using spaces or underscores in such codings.

    I had similar trouble in which I used Underscore. But it is not HTTP link. After removing the underscore from the file name, it worked fine.
    Kumar

+ 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. Select Case Statement
    By Gos-C in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-13-2008, 09:34 AM
  3. "Translating" numbers into words
    By Portuga in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2008, 11:44 AM
  4. Spell number
    By nowfal in forum Excel General
    Replies: 4
    Last Post: 08-20-2007, 04:21 PM
  5. [SOLVED] Variable Command Statment w/ Select Case
    By mpeplow in forum Excel General
    Replies: 1
    Last Post: 04-06-2007, 05:49 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