why does this not work comparing the 2 cell values?

aragon123321

New Member
Joined
Jul 6, 2015
Messages
26
What is wrong with this?
I want to compare my values from a range to a single cell.
My Value for Cell 22,2 is 4





Dim Cell, Result As String, I As Long


For I = 3 To 17


If Cells(I, 2).Value > Cell(22, 2).Value

Then
Call Step2(" Error")
Exit Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
How is it not working? Are you getting error messages (if so, what do they say), or are you just getting unexpected results?

For one, the "IF" and "THEN" need to be on the same line, and then you need an "END IF" at the bottom to close it out (unless you have it all on one line).
See: http://www.excel-easy.com/vba/if-then-statement.html

You also need a "NEXT" to go along with your "FOR".

Secondly, we don't know what your Step2 procedure does (you haven't posted that code).
 
Last edited:
Upvote 0
Rich (BB code):
For I = 3 To 17
    If Cells(I, 2).Value > Cell(22, 2).Value   Then    Call Step2(" Error")
next
Exit Sub
 
Upvote 0

Forum statistics

Threads
1,215,302
Messages
6,124,148
Members
449,146
Latest member
el_gazar

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