Statement is not analysing correctly

theta

Well-known Member
Joined
Jun 9, 2009
Messages
960
Hi all...this basic VBA statement is coming back with a fail

The debug shows each row count is the same, but the statements reads false

Code:
    Debug.Print PMNCodeSDR.Rows.Count
    Debug.Print PMNCodeEUR.Rows.Count
    Debug.Print PMNCodeUSD.Rows.Count
    
    If PMNCodeSDR.Rows.Count <> PMNCodeEUR.Rows.Count <> PMNCodeUSD.Rows.Count Then
       frmWait.lbxInfo.AddItem "Section 2 Named Ranges are not identical"
       Section2 = False
       Exit Function
    End If

Debug.print =
32
32
32

Any help appreciated
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
It should be something like

Code:
If PMNCodeSDR.Rows.Count <> PMNCodeEUR.Rows.Count And PMNCodeSDR.Rows.Count <> PMNCodeUSD.Rows.Count Then
 
Upvote 0
It's reading your if like this

If PMNCodeSDR.Rows.Count <> (PMNCodeEUR.Rows.Count <> PMNCodeUSD.Rows.Count) Then

so this part
(PMNCodeEUR.Rows.Count <> PMNCodeUSD.Rows.Count)
Resolves to FALSE (because they ARE both the same)

So it becomes

If PMNCodeSDR.Rows.Count <> False Then


Try adding an AND

If PMNCodeSDR.Rows.Count <> PMNCodeEUR.Rows.Count AND PMNCodeSDR.Rows.Count <> PMNCodeUSD.Rows.Count Then


Hope that helps.
 
Upvote 0
When using <>, one might have to test all three possibilities
Code:
If PMNCodeSDR.Rows.Count <> PMNCodeEUR.Rows.Count _
    AND PMNCodeSDR.Rows.Count <> PMNCodeUSD.Rows.Count _
    And PMNCodeEUR.Rows.Count <> PMNCodeUSD.Rows.Count Then
 
Upvote 0
That is a bit pants.

Any elegant solutions out there to tackle this?

I was going to use a number formula to add them, then divide by the count etc <> 1
 
Upvote 0
Might also try using MAX <> MIN

A = PMNCodeSDR.Rows.Count
B = PMNCodeEUR.Rows.Count
C = PMNCodeUSD.Rows.Count

If Application.Max(A,B,C) <> Application.Min(A,B,C) Then
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

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