Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
dim dim is offline
external usenet poster
 
Posts: 123
Default Compile Error ElseIf Without If.........But there is an If ! ???

Hi folks,

Can someone please try and debug this code for me? ARGHHHH!! I just don't
get it, why am I getting the compile error, there is obviously an 'If' so why
is it saying there's not?

If (Range("D9").Value) < 0 Then Range("D9").Select: Selection.ClearContents:
UserForm6.Show
ElseIf (Range("D9").Value) 125 Then Range("D9").Select:
Selection.ClearContents: UserForm6.Show
End If

Thankyou for any advice.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Compile Error ElseIf Without If.........But there is an If ! ???

When you have the action on the same line as the If , there is no closing
End If required. As you have Else clauses, you need to structre it like so

If (Range("D9").Value) < 0 Then
Range("D9").ClearContents:
UserForm6.Show
ElseIf (Range("D9").Value) 125 Then
Range("D9").ClearContents
UserForm6.Show
End If


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"dim" wrote in message
...
Hi folks,

Can someone please try and debug this code for me? ARGHHHH!! I just don't
get it, why am I getting the compile error, there is obviously an 'If' so
why
is it saying there's not?

If (Range("D9").Value) < 0 Then Range("D9").Select:
Selection.ClearContents:
UserForm6.Show
ElseIf (Range("D9").Value) 125 Then Range("D9").Select:
Selection.ClearContents: UserForm6.Show
End If

Thankyou for any advice.



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,073
Default Compile Error ElseIf Without If.........But there is an If ! ???

On Dec 30, 8:27 am, dim wrote:
Hi folks,

Can someone please try and debug this code for me? ARGHHHH!! I just don't
get it, why am I getting the compile error, there is obviously an 'If' so why
is it saying there's not?

If (Range("D9").Value) < 0 Then Range("D9").Select: Selection.ClearContents:
UserForm6.Show
ElseIf (Range("D9").Value) 125 Then Range("D9").Select:
Selection.ClearContents: UserForm6.Show
End If

Thankyou for any advice.


If Range("D9").Value < 0 Or Range("D9").Value 125 Then
Range("D9").ClearContents: UserForm6.Show
End If

Ken Johnson
  #4   Report Post  
Posted to microsoft.public.excel.misc
dim dim is offline
external usenet poster
 
Posts: 123
Default Compile Error ElseIf Without If.........But there is an If ! ?

Thanks Bob, your helping me out a lot lately! :-) And Ken I appreciate the
variation, I had'nt come across the 'Or' ability yet and it'll be very handy.

So one more question stemming from that........how many of the
'Or' can I use in a single line statement?
If...< 0 Or Range...125 Or Range...<24 Or Range....82 Or Range < 6 etc ...
Then...

Thanks again.

"Ken Johnson" wrote:

On Dec 30, 8:27 am, dim wrote:
Hi folks,

Can someone please try and debug this code for me? ARGHHHH!! I just don't
get it, why am I getting the compile error, there is obviously an 'If' so why
is it saying there's not?

If (Range("D9").Value) < 0 Then Range("D9").Select: Selection.ClearContents:
UserForm6.Show
ElseIf (Range("D9").Value) 125 Then Range("D9").Select:
Selection.ClearContents: UserForm6.Show
End If

Thankyou for any advice.


If Range("D9").Value < 0 Or Range("D9").Value 125 Then
Range("D9").ClearContents: UserForm6.Show
End If

Ken Johnson

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Compile Error ElseIf Without If.........But there is an If ! ?

I am not sure on the absolute limit, but I would guess that it is far more
than you would (should?) ever need.

But be wary with multiple ORs, you need to ensure that they are well
constructed. For instance in your example is 2 valid? You say

< 0 whereby 2 is not valid, and then add
< 24 whereby 2 is valid

Maybe you mean something like (just as an example)

IF (Range 4 AND Range <6) OR (Range 20 AND Range < 24) OR ... etc.

just pointing out some potential pit-falls.


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"dim" wrote in message
...
Thanks Bob, your helping me out a lot lately! :-) And Ken I appreciate the
variation, I had'nt come across the 'Or' ability yet and it'll be very
handy.

So one more question stemming from that........how many of the
'Or' can I use in a single line statement?
If...< 0 Or Range...125 Or Range...<24 Or Range....82 Or Range < 6 etc
...
Then...

Thanks again.

"Ken Johnson" wrote:

On Dec 30, 8:27 am, dim wrote:
Hi folks,

Can someone please try and debug this code for me? ARGHHHH!! I just
don't
get it, why am I getting the compile error, there is obviously an 'If'
so why
is it saying there's not?

If (Range("D9").Value) < 0 Then Range("D9").Select:
Selection.ClearContents:
UserForm6.Show
ElseIf (Range("D9").Value) 125 Then Range("D9").Select:
Selection.ClearContents: UserForm6.Show
End If

Thankyou for any advice.


If Range("D9").Value < 0 Or Range("D9").Value 125 Then
Range("D9").ClearContents: UserForm6.Show
End If

Ken Johnson





  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 93
Default Compile Error ElseIf Without If.........But there is an If !?

dim wrote:

Thanks Bob, your helping me out a lot lately! :-) And Ken I appreciate the
variation, I had'nt come across the 'Or' ability yet and it'll be very handy.

So one more question stemming from that........how many of the
'Or' can I use in a single line statement?
If...< 0 Or Range...125 Or Range...<24 Or Range....82 Or Range < 6 etc ...
Then...

Thanks again.

"Ken Johnson" wrote:


On Dec 30, 8:27 am, dim wrote:

Hi folks,

Can someone please try and debug this code for me? ARGHHHH!! I just don't
get it, why am I getting the compile error, there is obviously an 'If' so why
is it saying there's not?

If (Range("D9").Value) < 0 Then Range("D9").Select: Selection.ClearContents:
UserForm6.Show
ElseIf (Range("D9").Value) 125 Then Range("D9").Select:
Selection.ClearContents: UserForm6.Show
End If

Thankyou for any advice.


If Range("D9").Value < 0 Or Range("D9").Value 125 Then
Range("D9").ClearContents: UserForm6.Show
End If

Ken Johnson

Probably limited to compiler input line length.
  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,986
Default Compile Error ElseIf Without If.........But there is an If ! ???

"If" in VBA is not treated as a function and therefor does not require the
parentheses in the code structure. You can also omit the use of colons by
simply moving the next executable command to the next line. Ken Johnson has
eliminated all the unecessary code from you original code structure to
illustrate how it can be made more efficient with less detail.

"dim" wrote:

Hi folks,

Can someone please try and debug this code for me? ARGHHHH!! I just don't
get it, why am I getting the compile error, there is obviously an 'If' so why
is it saying there's not?

If (Range("D9").Value) < 0 Then Range("D9").Select: Selection.ClearContents:
UserForm6.Show
ElseIf (Range("D9").Value) 125 Then Range("D9").Select:
Selection.ClearContents: UserForm6.Show
End If

Thankyou for any advice.

  #8   Report Post  
Posted to microsoft.public.excel.misc
dim dim is offline
external usenet poster
 
Posts: 123
Default Compile Error ElseIf Without If.........But there is an If ! ?

Thankyou JLGWhiz also for the explanation. I hadn't seen your post before my
last reply!
Again any info regarding limits on the number of [Or]'s is appreciated. :-)

"JLGWhiz" wrote:

"If" in VBA is not treated as a function and therefor does not require the
parentheses in the code structure. You can also omit the use of colons by
simply moving the next executable command to the next line. Ken Johnson has
eliminated all the unecessary code from you original code structure to
illustrate how it can be made more efficient with less detail.

"dim" wrote:

Hi folks,

Can someone please try and debug this code for me? ARGHHHH!! I just don't
get it, why am I getting the compile error, there is obviously an 'If' so why
is it saying there's not?

If (Range("D9").Value) < 0 Then Range("D9").Select: Selection.ClearContents:
UserForm6.Show
ElseIf (Range("D9").Value) 125 Then Range("D9").Select:
Selection.ClearContents: UserForm6.Show
End If

Thankyou for any advice.

  #9   Report Post  
Posted to microsoft.public.excel.misc
dim dim is offline
external usenet poster
 
Posts: 123
Default Compile Error ElseIf Without If.........But there is an If ! ?

Thanks Bob,

I quickly typed my example, it wasn't written to be valid, just to
illustrate the question. I should have written something like.....= 0 Or....=
4 Or....= 14 etc etc. Either way, you've answered my question with the answer
I was hoping for! :-) Thanks again. L8rs.
  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Compile Error ElseIf Without If.........But there is an If ! ?

I thought that might be the case, but thought it best to point out the
potential pit-falls just in case.

Have a great 2008!

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"dim" wrote in message
...
Thanks Bob,

I quickly typed my example, it wasn't written to be valid, just to
illustrate the question. I should have written something like.....= 0
Or....=
4 Or....= 14 etc etc. Either way, you've answered my question with the
answer
I was hoping for! :-) Thanks again. L8rs.





  #11   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 93
Default Compile Error ElseIf Without If.........But there is an If !???

dim wrote:

Hi folks,

Can someone please try and debug this code for me? ARGHHHH!! I just don't
get it, why am I getting the compile error, there is obviously an 'If' so why
is it saying there's not?

If (Range("D9").Value) < 0 Then Range("D9").Select: Selection.ClearContents:
UserForm6.Show
ElseIf (Range("D9").Value) 125 Then Range("D9").Select:
Selection.ClearContents: UserForm6.Show
End If

Thankyou for any advice.

Incmplete code...the outer IF has no endif and maybe the compiler is
looking for an elseif in the absence of that endif.
  #12   Report Post  
Posted to microsoft.public.excel.misc
dim dim is offline
external usenet poster
 
Posts: 123
Default Compile Error ElseIf Without If.........But there is an If ! ?

Thanks folks,

I have it working now. :-D

"Robert Baer" wrote:

dim wrote:

Hi folks,

Can someone please try and debug this code for me? ARGHHHH!! I just don't
get it, why am I getting the compile error, there is obviously an 'If' so why
is it saying there's not?

If (Range("D9").Value) < 0 Then Range("D9").Select: Selection.ClearContents:
UserForm6.Show
ElseIf (Range("D9").Value) 125 Then Range("D9").Select:
Selection.ClearContents: UserForm6.Show
End If

Thankyou for any advice.

Incmplete code...the outer IF has no endif and maybe the compiler is
looking for an elseif in the absence of that endif.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile error:.......?? Geo Excel Discussion (Misc queries) 1 October 19th 07 01:01 PM
help with this error-Compile error: cant find project or library JackR Excel Discussion (Misc queries) 2 June 10th 06 09:09 PM
VBA Error Message "Compile Error...." Steve Excel Discussion (Misc queries) 3 July 15th 05 09:20 AM
How do I get rid of "Compile error in hidden module" error message David Excel Discussion (Misc queries) 4 January 21st 05 11:39 PM


All times are GMT +1. The time now is 07:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"