PDA

View Full Version : checking string in IF Loop



sathishesb
01-31-2011, 12:11 AM
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:help

GTO
01-31-2011, 12:49 AM
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

sathishesb
01-31-2011, 01:19 AM
what i need is,

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

GTO
01-31-2011, 01:34 AM
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