Stephen has attended:
Excel VBA Intro Intermediate course
IF statements within Excel VBA
In the below example please could you explain why I need to declare the variable as 3 if the following statement works without having 3 in the cell range (ie I have left it blank yet still returns yes,no).
My understanding was that this will only perform if x=3
Sub ifthen()
Dim x As Integer
x = 3
If x = 3 Then
Cells(1, 1).Value = "Yes"
Cells(1, 2).Value = "Please"
End If
Thankyou
RE: IF statements within Excel VBA
Hi Stephen, thanks for your query. It's a little unclear what you're trying to achieve there, I'm afraid. Could you give me a bit more information? Are you testing the value of the cell on the worksheet, and depending on whether it contains 3 outputting Yes & Please strings? If you are, then your code needs to test the cell value, not a variable value.
Anthony