If function problem

  • Thread starter Thread starter chrisnsmith
  • Start date Start date
C

chrisnsmith

Can someone explain to me why my Excel 2003 is not recognizing ( If )?
I've tried several codes with the If function and my code won't run.
If (this or that) Then...

and

If (this or that) Then....
Elseif (this or that) Then......
End If

In the first case the debugger says (End If without a block If).

In the second case the debugger says (ElseIf without a block If).
 
hi
usually means what it says. but we are not going to know untill you post
your code.

regards
FSt1
 
Post your ACTUAL code, not that pseudo-code... it is very hard to debug code
when you can't see the code.
 
I suspect the full code looks something like this:

If x = 1 or x=2 then y = 3
ElseIf x = 4 or x = 5 then y = 6
End if

If so, it should be

If x = 1 or x=2 then
y = 3
ElseIf x = 4 or x = 5 then
y = 6
End if

Incidentally, there is no need in VB/VBA to enclose the
conditions in parentheses; IMHO it needlessly clutters
up the code.
 
You must be familiar with the usual VB codes to be able to use macros.
As you are facing a problem related to conditional statement, I wil
describe briefly about its syntax

If you are just using one if statement then the syntax would be like
IF condition1 then
<statements>
………………………
End If

Now if you are using nested If-Else structure then the syntax would b
like
IF condition1 then
<statements>
………………….
ElseIF condition2 then
|<statements>
……………………..
End IF


Hope you get it.....


Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Posting---If function problem again 5
Run Macro If Cell have "x" value 0
VBA If Question 1
PowerPoint Help needed with VB 1
Still having problems with If --Elseif 13
show hide row if 4
Excel Applying Code to a Column 0
change certain cell colours in VBA 2

Back
Top