Else If Not Triggering

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Consider this code:
Rich (BB code):
    cntofreviewed = Application.CountIf(wshcore.Range("Q:Q"), 1)
    If cntofreviewed = 0 Then 'nothing has been reviewed and submitted
        MsgBox "Of the " & wshmain.Range("D3") & ", 0 records have been reviewed and submitted." & Chr(13) & "Please review, edit and submit the records before reconciling.", 48, "RECONCILIATION NOT APPLICABLE"
        Exit Sub
    ElseIf cntofreview > 1 And cntofreview < wshmain.Range("D3") Then
        pro1 = MsgBox("There are " & wshmain.Range("D4") & " records not yet reviewed and submitted." & Chr(13) & "Do you wish to continue editing?", 36, "RECONCILIATION")
        If pro1 = vbYes Then
            Exit Sub
        End If
    End If

In my example,
cntofreviewed = 26
wshmain.range("D3") = 45

If I've written this code correctly, the elseif statementin blue should trigger a true situation. It's not. It's passed over.
Is there something I'm missing here?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
you have written elseif cntofreview

the variable is cnttofreviwed

Do you not have option explicit set?
 
Upvote 0
Hi Dryver ... thanks you for the second set of eyes. Sometimes when you look at something for too long, the obvious just isn't very obvious.
Where do I put "option explicit", what does it do?
 
Upvote 0
You can set it in the settings to always appear or place it at the top of the module page in the declarations section.

It forces you to declare your variables with dim statements,

Usually the best way.

I always try and put a capital in my variable names (except x,y etc)

that way, if you had called your variable CntoFreViewed, you can type it as it is and it would capitalise itself allowing you to
see you ahve typed it right, also had you tried to run the macro it would ahve jumped straight to the wrongly spelt variable
and stated that the variable was not defined.

Can save a lot of work.
 
Upvote 0

Forum statistics

Threads
1,214,569
Messages
6,120,286
Members
448,953
Latest member
Dutchie_1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top