if statements within excel

Public Schedule Face-to-Face & Virtual Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » IF statements within Excel VBA

IF statements within Excel VBA

resolvedResolved · Medium Priority · Version 2003

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

Tue 22 Mar 2011: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Date and time

CTRL+ SEMICOLON then SPACE then CTRL+SHIFT+ SEMICOLON

View all Excel hints and tips


Server loaded in 0.07 secs.