Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
"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. |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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.... ![]() '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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
#7
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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.... ![]() '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 |
#8
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
#9
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
#10
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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.... ![]() '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. |
#11
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
#12
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Compile error:.......?? | Excel Discussion (Misc queries) | |||
help with this error-Compile error: cant find project or library | Excel Discussion (Misc queries) | |||
VBA Error Message "Compile Error...." | Excel Discussion (Misc queries) | |||
How do I get rid of "Compile error in hidden module" error message | Excel Discussion (Misc queries) |