Consulting

Results 1 to 4 of 4

Thread: checking string in IF Loop

  1. #1

    checking string in IF Loop

    Hi Guys,
    I have tried with the below code

    If validity = VALID Then
    Sheet1.Cells(i, 3) = "1"
    Else
    Sheet1.Cells(i, 3) = "2"
    End If
    Next i

    Validity is a variable, VALID is a the value i want to check with the stored value in the variable Validity. but i couldn't..
    please help me to compare the string using IF loop

    Thanks in advance ... plzzz help me

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi sathishesb,

    I would suggest you attach a small workbook that replicates what you are trying to do. There is not enough in the above to see why its not working.

    Mark

  3. #3
    what i need is,

    if variable name='string value to be compared' then
    .
    .
    code
    .
    endif

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Option Explicit
        
    Sub exa()
    Dim validity As String
        
    Const VALID As String = "Mary Beth"
        
        validity = "Mary Jo"
        
        If validity = VALID Then
            Sheet1.Cells(1, 3) = 1
        Else
            Sheet1.Cells(1, 3) = 2
        End If
    End Sub

Posting Permissions

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