PC Review


Reply
Thread Tools Rate Thread

Compile error "Else without if"

 
 
Morlin
Guest
Posts: n/a
 
      13th May 2009
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.

 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      13th May 2009
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.
>
>

 
Reply With Quote
 
Morlin
Guest
Posts: n/a
 
      13th May 2009
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 <Mi...@discussions.microsoft.com> 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 -


 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      13th May 2009
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 <Mi...@discussions.microsoft.com> 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 -

>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      13th May 2009
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Acess error: "Compile Error: Canot find Project or Library" John Morgan Microsoft Access 10 1st Dec 2008 03:07 AM
Stop error message - "Compile Error in hidden module appearing" =?Utf-8?B?SG93YXJkMTg=?= Microsoft Word Document Management 1 20th Oct 2005 05:12 PM
error message in Excel 2003 "compile error in hidden module" =?Utf-8?B?ZGlzY29kYWxleQ==?= Microsoft Excel Crashes 3 29th Jul 2005 10:01 PM
Re: Getting "compile error" "method or data member not found" on reinstall Bp Microsoft Excel Programming 0 23rd Apr 2004 04:42 PM
"Compile Error in hidden module" visual basic error heymikey Microsoft Outlook Discussion 0 11th Nov 2003 10:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:09 PM.