Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Compile error "Else without if"

Help.

I had a userform that I can fill out and then save to a spreadsheet.
Then I can Look up the information and have it put back into a
spreadsheet. To make changes. Then it is necessary to save the
changes again.

If CheckMilo Then Cells(NextRow, 8) = "2"
Else
Cells(NextRow, 8) = ""
End If

this is one of about 25-30 check boxes I need to be able to affect. I
get an error Compile error "else without if" could somebody tell me
how to right it so I don't get the error.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Compile error "Else without if"

Hi

Without seeing the rest of the code I have no idea if the code works but
this should make it compile

If CheckMilo Then
Cells(NextRow, 8) = "2"
Else
Cells(NextRow, 8) = ""
End If

Mike

"Morlin" wrote:

Help.

I had a userform that I can fill out and then save to a spreadsheet.
Then I can Look up the information and have it put back into a
spreadsheet. To make changes. Then it is necessary to save the
changes again.

If CheckMilo Then Cells(NextRow, 8) = "2"
Else
Cells(NextRow, 8) = ""
End If

this is one of about 25-30 check boxes I need to be able to affect. I
get an error Compile error "else without if" could somebody tell me
how to right it so I don't get the error.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Compile error "Else without if"

I gotta ask. How is that different from what I had? do you have to
have them on seperate lines like that so instead of 4 lines of code
that I had it needs to be 5?

Thanks for the answer. it worked I just need to know if that is
why.




On May 13, 12:42*pm, Mike H wrote:
Hi

Without seeing the rest of the code I have no idea if the code works but
this should make it compile

If CheckMilo Then
* * * * *Cells(NextRow, 8) = "2"
Else
* * * * * Cells(NextRow, 8) = ""
End If

Mike



"Morlin" wrote:
Help.


I had a userform that I can fill out and then save to a spreadsheet.
Then I can Look up the information and have it put back into a
spreadsheet. *To make changes. *Then it is necessary to save the
changes again.


* * *If CheckMilo Then Cells(NextRow, 8) = "2"
Else
* * Cells(NextRow, 8) = ""
End If


this is one of about 25-30 check boxes I need to be able to affect. *I
get an error Compile error *"else without if" *could somebody tell me
how to right it so I don't get the error.- Hide quoted text -


- Show quoted text -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Compile error "Else without if"

Hi,

It's simply the correct syntax when using ELSE

this is OK

if myvalue = 10 then yourvalue = 11

but what you had isn't.

have a look here

http://office.microsoft.com/en-us/ex...117011033.aspx

Mike


"Morlin" wrote:

I gotta ask. How is that different from what I had? do you have to
have them on seperate lines like that so instead of 4 lines of code
that I had it needs to be 5?

Thanks for the answer. it worked I just need to know if that is
why.




On May 13, 12:42 pm, Mike H wrote:
Hi

Without seeing the rest of the code I have no idea if the code works but
this should make it compile

If CheckMilo Then
Cells(NextRow, 8) = "2"
Else
Cells(NextRow, 8) = ""
End If

Mike



"Morlin" wrote:
Help.


I had a userform that I can fill out and then save to a spreadsheet.
Then I can Look up the information and have it put back into a
spreadsheet. To make changes. Then it is necessary to save the
changes again.


If CheckMilo Then Cells(NextRow, 8) = "2"
Else
Cells(NextRow, 8) = ""
End If


this is one of about 25-30 check boxes I need to be able to affect. I
get an error Compile error "else without if" could somebody tell me
how to right it so I don't get the error.- Hide quoted text -


- Show quoted text -



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Compile error "Else without if"

It's the difference between a single line if/then/else statement and a block
if/end/else statement.

If CheckMilo Then Cells(NextRow, 8) = 2 Else Cells(NextRow, 8) = ""

Would have worked ok. But for me, I find it miserable to read--just too easy to
miss something important.

I do my best to use the block if statement:

If CheckMilo Then
Cells(NextRow, 8) = "2"
Else
Cells(NextRow, 8) = ""
end if

I think it's easier to read and update.



Morlin wrote:

Help.

I had a userform that I can fill out and then save to a spreadsheet.
Then I can Look up the information and have it put back into a
spreadsheet. To make changes. Then it is necessary to save the
changes again.

If CheckMilo Then Cells(NextRow, 8) = "2"
Else
Cells(NextRow, 8) = ""
End If

this is one of about 25-30 check boxes I need to be able to affect. I
get an error Compile error "else without if" could somebody tell me
how to right it so I don't get the error.


--

Dave Peterson
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
Get a VB "Compile error in hidden module: DistMon" at start Dave Excel Discussion (Misc queries) 1 August 10th 09 12:19 AM
How correct (or remove) "Compile error in hidden module: DistMon" wlfoote Excel Discussion (Misc queries) 1 June 6th 09 02:57 AM
"compile error in hidden module": DISTMOD -- ideas to fix it?? Clare Excel Discussion (Misc queries) 3 May 29th 08 01:44 AM
Compile Error in Excel 2004 when Inputbox contains "VBCRLF" QTP Professional Excel Discussion (Misc queries) 1 November 18th 05 11:47 PM
Getting "compile error" "method or data member not found" on reinstall Bp Excel Programming 1 April 23rd 04 04:42 PM


All times are GMT +1. The time now is 11:56 AM.

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

About Us

"It's about Microsoft Excel"