+ Reply to Thread
Results 1 to 6 of 6

Character checking problem in an if statement

  1. #1
    Registered User
    Join Date
    05-27-2013
    Location
    Buellton, California
    MS-Off Ver
    Excel 2007
    Posts
    26

    Character checking problem in an if statement

    Hi all,
    I am trying to change a variable depending on a character in a string (it should be different if the character is a V, W or L). Right now the code doesn't seem to get into the second If statement and I am not sure why, because it should go to the ElseIf statement to check that condition. None of the conditions are being met.
    Is there a problem with my method of checking if the variable is a certain character?
    Please let me know if there is method to do this, or a fix to my code to get it working.

    Please Login or Register  to view this content.
    I tried
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    also, but neither seems to work.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Character checking problem in an if statement

    Hi, KeithMale,

    amybe use a Select case:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Character checking problem in an if statement

    You have one if and with else if statement.
    The code first checks this line: If it is true, it jumps to the end of it.

    If IsNumeric(J) Then

    It is false, it goes to

    ElseIf J = LetterV Then
    If this true, you have further nested loop. It is false, it goes to the bottom of if end

  4. #4
    Registered User
    Join Date
    05-27-2013
    Location
    Buellton, California
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Character checking problem in an if statement

    I didn't think of the select case, Thanks HaHoBe!
    You are right AB33, it was jumping to the end because none of the conditions were being met. Guess I should be more specific in my description of the problem.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Character checking problem in an if statement

    If it is returning false, you need to check this line

    Please Login or Register  to view this content.
    Step over using F8 (Using local window)and see what value do you get when the code hits that line.

  6. #6
    Registered User
    Join Date
    05-27-2013
    Location
    Buellton, California
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Character checking problem in an if statement

    I changed it to the Select Case instead of an If Else, so there is no longer a problem.

    That F8 tip is very nice though. Thanks

+ 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. Problem Checking Range.Name Through "IF" Statement
    By neese016 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-26-2011, 09:42 PM
  2. Checking Character Length in a specific row and column
    By crisshinn in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-27-2011, 07:02 AM
  3. Checking if an entry contains a certain character
    By Hitch75 in forum Excel General
    Replies: 3
    Last Post: 03-03-2011, 12:53 PM
  4. Checking to see if a character exists in a string
    By WKM in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 06-04-2010, 11:59 PM
  5. [SOLVED] Checking a String's last character
    By Ren in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-02-2006, 01:10 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