Consulting

Results 1 to 3 of 3

Thread: if condition is variable + number

  1. #1

    if condition is variable + number

    I am not sure the best way to ask this question, i imagine the answer is easy but I am not sure how to look it up online (I always try that first). it is possible it is working and I am just not realizing it. I was just testing up to the end of the case statement so maybe I would not see the math until after the case statement

    I want an if statement that says

    if slidenumber = startnumber + 3 then....

    the trouble is that it keeps saying that Slidenumber = startnumber and does not want to add the 3

    (side note: this if is part of a case statement that there are 22 options...so need to be able to say +3. then the next conditions would say +4)


    Below is a little bit of my actual code. it seems the 'math' portion of the ifthen conditions is not working
     If SN = SiteSlidesStart Then
                  FN = "Alaska Slide 1"
    ElseIf SN = SiteSlidesStart + 1 Then
                FN = "Alaska Slide 2"
    ElseIf SN = SiteSlidesStart + 2 Then
                  FN = "ABQ Slide 1"
    ElseIf SN = SiteSlidesStart + 3 Then
                FN = "ABQ Slide 2"
    EndIf
    Last edited by Paul_Hossler; 06-27-2022 at 10:04 AM.

  2. #2
    nevermind, it works fine. I just did not try the code after the case statement (which is where I would see the different slide numbers)

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,380
    Location
    1. I changed your HTML tags to CODE tags (the # icon) and formatted it a little

    2. Hard to tell without seeing the entire macro, but I'd use Select Case instead since I vaguely recall that there's a limit on how many If Then ElseIf's you can have


    Select Case SN
        Case  SiteSlidesStart
           FN = "Alaska Slide 1"
    
        Case SlidesStart + 1
           FN = "Alaska Slide 2"
    
        Case SiteSlidesStart + 2
           FN = "ABQ Slide 1"
    
        Case SiteSlidesStart + 3
            FN = "ABQ Slide 2"
    
    .....
    
    End Select
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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