Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default If Then Else Statements

I have the following code in my auto_open. I keep getting an error msg
stateing "Else without an IF". Can someone tell me where my coding is
going wrong? What I'm doing is checking to see if a persons name is at
f1 and if false, then run macro 2 asking for it. But, if no name is ther
and it's after the trial date, then shut down immediately.
Thanks


Sub Auto_Open() 'This first "IF" statement checks for a recorded name at
f1
If Worksheets("data").Range("f1") < 1 Then Call Macro2
ElseIf Now Worksheets("data").Range("f10") Then 'This shuts down the
program after 10/31/03
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.Quit
End If
End Sub
Rem Call Macro2
Rem End Sub
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 7/30/2003 by DLS
'Sub GetInput()
Dim MyInput 'This line of code is optional
MyInput = InputBox("Enter Company Name")
Range("data!f2").Value = MyInput
MyInput = InputBox("Enter your Name")
Range("data!f1").Value = MyInput
msgbox ("Hello ") & MyInput
End Sub

DLS

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default If Then Else Statements

A simple fix

Move Call Macro2 to the next line

If Worksheets("data").Range("f1") < 1 Then

Call Macro2
ElseIf Now Worksheets("data").Range("f10") Then .....


steve

<DLS wrote in message ...
I have the following code in my auto_open. I keep getting an error msg
stateing "Else without an IF". Can someone tell me where my coding is
going wrong? What I'm doing is checking to see if a persons name is at
f1 and if false, then run macro 2 asking for it. But, if no name is ther
and it's after the trial date, then shut down immediately.
Thanks


Sub Auto_Open() 'This first "IF" statement checks for a recorded name at
f1
If Worksheets("data").Range("f1") < 1 Then Call Macro2
ElseIf Now Worksheets("data").Range("f10") Then 'This shuts down the
program after 10/31/03
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.Quit
End If
End Sub
Rem Call Macro2
Rem End Sub
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 7/30/2003 by DLS
'Sub GetInput()
Dim MyInput 'This line of code is optional
MyInput = InputBox("Enter Company Name")
Range("data!f2").Value = MyInput
MyInput = InputBox("Enter your Name")
Range("data!f1").Value = MyInput
msgbox ("Hello ") & MyInput
End Sub

DLS

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default If Then Else Statements

Hi DLS,

Here's a corrected version:

Sub Auto_Open()
If Worksheets("data").Range("f1") < 1 Then
Call Macro2
ElseIf Now Worksheets("data").Range("f10") Then
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.Quit
End If
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


<DLS wrote in message ...
I have the following code in my auto_open. I keep getting an error msg
stateing "Else without an IF". Can someone tell me where my coding is
going wrong? What I'm doing is checking to see if a persons name is at
f1 and if false, then run macro 2 asking for it. But, if no name is ther
and it's after the trial date, then shut down immediately.
Thanks


Sub Auto_Open() 'This first "IF" statement checks for a recorded name at
f1
If Worksheets("data").Range("f1") < 1 Then Call Macro2
ElseIf Now Worksheets("data").Range("f10") Then 'This shuts down the
program after 10/31/03
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.Quit
End If
End Sub
Rem Call Macro2
Rem End Sub
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 7/30/2003 by DLS
'Sub GetInput()
Dim MyInput 'This line of code is optional
MyInput = InputBox("Enter Company Name")
Range("data!f2").Value = MyInput
MyInput = InputBox("Enter your Name")
Range("data!f1").Value = MyInput
msgbox ("Hello ") & MyInput
End Sub

DLS

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default If Then Else Statements

Sub Auto_Open()

If Worksheets("data").Range("f1") < 1 Then Call Macro2

If Now Worksheets("data").Range("f10") Then
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.Quit
End If

End Sub

Uzytkownik <DLS napisal w wiadomosci
...
I have the following code in my auto_open. I keep getting an error msg
stateing "Else without an IF". Can someone tell me where my coding is
going wrong? What I'm doing is checking to see if a persons name is at
f1 and if false, then run macro 2 asking for it. But, if no name is ther
and it's after the trial date, then shut down immediately.
Thanks


Sub Auto_Open() 'This first "IF" statement checks for a recorded name at
f1
If Worksheets("data").Range("f1") < 1 Then Call Macro2
ElseIf Now Worksheets("data").Range("f10") Then 'This shuts down the
program after 10/31/03
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.Quit
End If
End Sub
Rem Call Macro2
Rem End Sub
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 7/30/2003 by DLS
'Sub GetInput()
Dim MyInput 'This line of code is optional
MyInput = InputBox("Enter Company Name")
Range("data!f2").Value = MyInput
MyInput = InputBox("Enter your Name")
Range("data!f1").Value = MyInput
msgbox ("Hello ") & MyInput
End Sub

DLS

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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
if statements jrt Excel Worksheet Functions 3 December 6th 07 09:59 PM
If Statements Sr Accountant[_2_] Excel Discussion (Misc queries) 3 October 12th 07 07:45 PM
IF Statements (Mutliple Statements) Deezel Excel Worksheet Functions 3 October 19th 06 06:13 AM
IF and MAX statements bob Excel Worksheet Functions 5 April 2nd 06 04:33 AM
if statements help Smurphy New Users to Excel 2 February 6th 06 09:23 PM


All times are GMT +1. The time now is 07:17 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"