ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ElseIf question (https://www.excelbanter.com/excel-programming/426404-elseif-question.html)

TomK76

ElseIf question
 
I am trying to write code so that when an entry is made, excel verifies
necessary entries in other ranges before saving the change. I started with
code that worked:

If Not Application.Intersect(Target, Me.Range("O3")) Is Nothing Then

If IsNumeric(Target) Then

If Not Application.WorksheetFunction.CountA(Range("Filler Scrap")) 0 Then

Dim FScrapButton As Integer

intFScrapButton = MsgBox("Please Enter Scrap!", vbOKOnly +
vbExclamation, "Filler Scrap!")

Range("O3:P4").Select

Selection.ClearContents

Range("C29").Select

ElseIf Not Application.WorksheetFunction.CountA(Range("C40:C4 6")) 0 Then

Dim LaborButton As Integer

intLaborButton = MsgBox("Please Enter Labor!", vbOKOnly +
vbExclamation, "Labor!")

Range("O3:P4").Select

Selection.ClearContents

Range("C40").Select

Else

Me.Parent.Save

Dim intButtonPressed As Integer

intButtonPressed = MsgBox("Your Tracking Sheet has been Saved. Would
you like to Print?", vbYesNo + vbQuestion)

If intButtonPressed = vbYes Then

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

But when I add another "ElseIF" statement after the first, excel completely
ignores the ElseIF statements and goes directly to Else statement.

Is there a limit to how many "ElseIF" functions I can use?

Nigel[_2_]

ElseIf question
 
AFAIK There is no practical limit to the number of ElseIf statements you can
have.

--

Regards,
Nigel




"TomK76" wrote in message
...
I am trying to write code so that when an entry is made, excel verifies
necessary entries in other ranges before saving the change. I started with
code that worked:

If Not Application.Intersect(Target, Me.Range("O3")) Is Nothing Then

If IsNumeric(Target) Then

If Not Application.WorksheetFunction.CountA(Range("Filler Scrap")) 0
Then

Dim FScrapButton As Integer

intFScrapButton = MsgBox("Please Enter Scrap!", vbOKOnly +
vbExclamation, "Filler Scrap!")

Range("O3:P4").Select

Selection.ClearContents

Range("C29").Select

ElseIf Not Application.WorksheetFunction.CountA(Range("C40:C4 6")) 0
Then

Dim LaborButton As Integer

intLaborButton = MsgBox("Please Enter Labor!", vbOKOnly +
vbExclamation, "Labor!")

Range("O3:P4").Select

Selection.ClearContents

Range("C40").Select

Else

Me.Parent.Save

Dim intButtonPressed As Integer

intButtonPressed = MsgBox("Your Tracking Sheet has been Saved. Would
you like to Print?", vbYesNo + vbQuestion)

If intButtonPressed = vbYes Then

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

But when I add another "ElseIF" statement after the first, excel
completely
ignores the ElseIF statements and goes directly to Else statement.

Is there a limit to how many "ElseIF" functions I can use?



Rick Rothstein

ElseIf question
 
You didn't show us all your code. It looks like you have three nested
If..Then blocks of code... my guess is you tried inserting your ElseIf into
the wrong nested If..Then block. If you showed us all of your original code
(dealing with the three nested If..Then blocks) and told us what you wanted
to do, perhaps someone here could show you how to to it.

--
Rick (MVP - Excel)


"TomK76" wrote in message
...
I am trying to write code so that when an entry is made, excel verifies
necessary entries in other ranges before saving the change. I started with
code that worked:

If Not Application.Intersect(Target, Me.Range("O3")) Is Nothing Then

If IsNumeric(Target) Then

If Not Application.WorksheetFunction.CountA(Range("Filler Scrap")) 0
Then

Dim FScrapButton As Integer

intFScrapButton = MsgBox("Please Enter Scrap!", vbOKOnly +
vbExclamation, "Filler Scrap!")

Range("O3:P4").Select

Selection.ClearContents

Range("C29").Select

ElseIf Not Application.WorksheetFunction.CountA(Range("C40:C4 6")) 0
Then

Dim LaborButton As Integer

intLaborButton = MsgBox("Please Enter Labor!", vbOKOnly +
vbExclamation, "Labor!")

Range("O3:P4").Select

Selection.ClearContents

Range("C40").Select

Else

Me.Parent.Save

Dim intButtonPressed As Integer

intButtonPressed = MsgBox("Your Tracking Sheet has been Saved. Would
you like to Print?", vbYesNo + vbQuestion)

If intButtonPressed = vbYes Then

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

But when I add another "ElseIF" statement after the first, excel
completely
ignores the ElseIF statements and goes directly to Else statement.

Is there a limit to how many "ElseIF" functions I can use?




All times are GMT +1. The time now is 12:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com