if statements within excel
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

replyReply Fri 11 Mar 2011, 15:34Delegate Stephen said...

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

For upcoming training course dates see: Pricing & availability

replyReply Tue 15 Mar 2011, 21:01Trainer Anthony said...

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.

 

Please browse our web site to find out more about
excel+vba+training and other Microsoft training courses.

Excel tip:

Change the Value of a Constant

When using a named constant in a worksheet, you may wish to change the value of that constant.

From the 'Insert' menu, select 'Name', then select 'Define'.

In the 'Define Name' dialog box, select the constant that you want to change.
Change the value in the 'Refers To' box.
Click OK.

Wherever that named constant has been used it will now use its new value.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard