+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    10-12-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    76

    Conditional statement

    Hi there

    I have an set of conditional statements to check which i'm not sure whether to use IF or CASE statement. can u please advice

    Find below the code

    Code:
        If strOnA1 = "Yes" Then
                strcode = "Hi " + PersonName + " Welcome to Hotel " + HotelName
        ElseIf strOnA2 = "Yes" Then
                strcode = "Hi " + PersonName + " Welcome to Hotel " + HotelName
        ElseIf strOnA3 = "Yes" Then
                strcode = "Hi " + PersonName + " Welcome to Hotel " + HotelName
        ElseIf strOnA4 = "Yes" Then
                strcode = "Hi " + PersonName + " Welcome to Hotel " + HotelName
        End If
    
        If strOnA1 = "No" Then
                strcode = "Hi " + PersonName + " Sorry, please signup at  " + HotelName
        ElseIf strOnA2 = "No" Then
                strcode = "Hi " + PersonName + " Sorry, please signup at  " + HotelName
        ElseIf strOnA3 = "No" Then
                strcode = "Hi " + PersonName + " Sorry, please signup at  " + HotelName
        ElseIf strOnA4 = "No" Then
                strcode = "Hi " + PersonName + " Sorry, please signup at  " + HotelName
        End If
    I'm passing strcode to another function which generates email so
    Code:
    .subject = strcode
    But for some reason the right condition is not getting picked up
    Last edited by captedgar; 01-28-2010 at 08:07 PM.

  2. #2
    Forum Moderator Richard Buttrey's Avatar
    Join Date
    02-15-2008
    Location
    Grappenhall, UK
    MS-Off Ver
    Excel for Windows & Mac - all versions.
    Posts
    5,826

    Re: Conditional statement

    Hi

    Without knowing which condition is being picked up and which condition you think should be picked up it's difficult to advise. Don't worry at the moment about the difference between If..Then and Select Case structures, the first thing to reconcile is the basic problem.
    Can you upload an example workbook so that we can see the problem in context. If you do add a note saying what you expect should be happening.

    Regards
    Richard Buttrey

    If this was useful then please rate it appropriately.

    Click the small star icon at the bottom left of my post.

  3. #3
    Registered User
    Join Date
    10-12-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    76

    Re: Conditional statement

    Hi there

    I have attached a simple spreadsheet with a table in it
    All the cells except the headers in the tables are conditional formatted so that
    if i select a cell in the table as No, the colour of the cell turns red
    if i select Yes, the cell color turns green and
    if i select NA, the cell color turns orange.

    My code is below

    Code:
     
    
    If strOnG8 = "Yes" and Range(RangeFinder("A") + strCurrentRow).Value2  Then
                strcode = "Hi " + PersonName + " Welcome to Hotel " + HotelName
        ElseIf strOnH8 = "Yes" and Range(RangeFinder("B") + strCurrentRow).Value2  Then
                strcode = "Hi " + PersonName + " Welcome to Hotel " + HotelName
        ElseIf strOnI8 = "Yes" and Range(RangeFinder("C") + strCurrentRow).Value2  Then
                strcode = "Hi " + PersonName + " Welcome to Hotel " + HotelName
        ElseIf strOnJ8 = "Yes" and Range(RangeFinder("D") + strCurrentRow).Value2  Then
                strcode = "Hi " + PersonName + " Welcome to Hotel " + HotelName
    End If
    
    If strOnG8 = "NA" and Range(RangeFinder("A") + strCurrentRow).Value2 Then
                strcode = "Hi " + PersonName + " Sorry, please signup at  " + HotelName
        ElseIf strOnH8 = "NA" and Range(RangeFinder("B") + strCurrentRow).Value2  Then
                strcode = "Hi " + PersonName + " Sorry, please signup at  " + HotelName
        ElseIf strOnI8 = "NA" and Range(RangeFinder("C") + strCurrentRow).Value2  Then
                strcode = "Hi " + PersonName + " Sorry, please signup at  " + HotelName
        ElseIf strOnJ8 = "NA" and Range(RangeFinder("D") + strCurrentRow).Value2  Then
                strcode = "Hi " + PersonName + " Sorry, please signup at  " + HotelName
    End If
    
    'RangeFinder, strcode, PersonName and HotelName are all global variables called in
    different functions withinin the code and they are all working fine. There is no dependency 
    of them to the above code
    When i need to select a particular row as Yes or NA, my IF statement is breaking logic in
    picking the right strcode value independent of whatever the values are in the other cells in
    the table

    Please advice
    Attached Files Attached Files

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.2.0