+ Reply to Thread
Results 1 to 7 of 7

Case statement dependent on for loop?

  1. #1
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Case statement dependent on for loop?

    I am trying to write a case statement or, number of case statements that is dependent on a loop. For example here is what I've tried to do:

    Please Login or Register  to view this content.
    Instead of typing out 5 case statements, I would like it to check the cableod value through the 5 cells as you can see. This doesn't work however. Is this possible?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Case statement dependent on for loop?

    What is cableod and what are you actually trying to check it for?

    Is it to see if it falls between the values in columns A and B, inclusively, on row i?

    If it is then perhaps a simple If would work.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: Case statement dependent on for loop?

    AH, so I should just use an if statement instead of a case statement? I was new to select case, so I though I had to have a case statement with the select case.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Case statement dependent on for loop?

    A Select Case should have worked really, but it's normally used when there's more than one outcome/criteria.

  5. #5
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: Case statement dependent on for loop?

    I'm having some trouble getting this to work, and I think it is because of the ws6.range().value statement. If replace this with just numbers, it works but not with the ws6.range statement. I've tried it with a case statement too. For example, case 1 to 8 works if say cableod is 5, but case ws6.range("A1").value to ws6.range("B1").value doesn't work....
    Last edited by hockeyadc; 06-04-2013 at 01:26 PM.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Case statement dependent on for loop?

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  7. #7
    Registered User
    Join Date
    11-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    80

    Re: Case statement dependent on for loop?

    I think I got it actually. I had to make separate variables to compare, and set them as integers.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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