#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 270
Default If Then Else

What am I doing wrong in this simple statement - it fails in the line
just before **Do Stuff**

Dim myFileName, myName, myWorkbookName As String
myName = Sheets("Data Input").Range("D1").Value
myFileName = "Personal Data-" & myName & ".xls"
myWorkbookName = ActiveWorkbook.Name

If "Personal Data.xls" = ActiveWorkbook.Name Then
GoTo myMark
ElseIf
myWorkbookName < myFileName Then

***** Do Stuff********

End If

Thanks Sandy


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Art Art is offline
external usenet poster
 
Posts: 587
Default If Then Else

Sandy,

You need to have:
ElseIf myWorkbookName < myFileName Then
all on one line.

Also, even though you didn't ask, it's generally not good to use GoTo.
Possibly better in your case would be to have a separate sub that does what
you want in the case of equality.



"Sandy" wrote:

What am I doing wrong in this simple statement - it fails in the line
just before **Do Stuff**

Dim myFileName, myName, myWorkbookName As String
myName = Sheets("Data Input").Range("D1").Value
myFileName = "Personal Data-" & myName & ".xls"
myWorkbookName = ActiveWorkbook.Name

If "Personal Data.xls" = ActiveWorkbook.Name Then
GoTo myMark
ElseIf
myWorkbookName < myFileName Then

***** Do Stuff********

End If

Thanks Sandy



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 270
Default If Then Else

Thanks for your help but why is it so bad to have a GoTo?

Sandy

"Art" wrote in message
...
Sandy,

You need to have:
ElseIf myWorkbookName < myFileName Then
all on one line.

Also, even though you didn't ask, it's generally not good to use GoTo.
Possibly better in your case would be to have a separate sub that does
what
you want in the case of equality.



"Sandy" wrote:

What am I doing wrong in this simple statement - it fails in the line
just before **Do Stuff**

Dim myFileName, myName, myWorkbookName As String
myName = Sheets("Data Input").Range("D1").Value
myFileName = "Personal Data-" & myName & ".xls"
myWorkbookName = ActiveWorkbook.Name

If "Personal Data.xls" = ActiveWorkbook.Name Then
GoTo myMark
ElseIf
myWorkbookName < myFileName Then

***** Do Stuff********

End If

Thanks Sandy





  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Art Art is offline
external usenet poster
 
Posts: 587
Default If Then Else

GoTo's have a tendancy to result in Spaghetti Code
http://en.wikipedia.org/wiki/Spaghetti_code

It makes it harder to know where the program will be at any given time.
Another problem is that if you pass the GoTo (that is, didn't jump), you may
wind up at that GoTo point anyway -- this may or may not be desireable
depending on what you want.

A more structured approach tends to be easier to debug.

Now in VBA you can't entirely avoid GoTo's. Error handling (as far as I
know) only works by way of a GoTo.



"Sandy" wrote:

Thanks for your help but why is it so bad to have a GoTo?

Sandy

"Art" wrote in message
...
Sandy,

You need to have:
ElseIf myWorkbookName < myFileName Then
all on one line.

Also, even though you didn't ask, it's generally not good to use GoTo.
Possibly better in your case would be to have a separate sub that does
what
you want in the case of equality.



"Sandy" wrote:

What am I doing wrong in this simple statement - it fails in the line
just before **Do Stuff**

Dim myFileName, myName, myWorkbookName As String
myName = Sheets("Data Input").Range("D1").Value
myFileName = "Personal Data-" & myName & ".xls"
myWorkbookName = ActiveWorkbook.Name

If "Personal Data.xls" = ActiveWorkbook.Name Then
GoTo myMark
ElseIf
myWorkbookName < myFileName Then

***** Do Stuff********

End If

Thanks Sandy






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



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