If cell is > 0

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
727
Office Version
  1. 2016
Platform
  1. Windows
I can't for the life of me figure out why this isn't working. It seems so straight forward, what am I missing?

This is what I have:

s.xlsx
EH
204Complete
205Complete
206Complete
207N/A
208Complete
209Complete
210Complete
211N/A
212Complete
2135
214Complete
215Complete
216Complete
217Complete
218Complete
219Complete
s


I'm trying to identify the cells in column E that are greater than 0.

When I run the code, all cells return True.

VBA Code:
Sub test()
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    For y = 2 To lr
        If Rows(y).Hidden = False And Range("E" & y) > 0 Then Range("H" & y) = True
    Next y
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
None of them are blank so all are greater than 0? I have to admit that it's not intuitive that the default for that comparison works that way.
What exactly are you trying to do? I only see 1 cell with a number and none of the rest are blank. Perhaps you want to only compare numbers? Then maybe
VBA Code:
If Rows(y).Hidden = False And Application.WorksheetFunction.IsNumber(Range("E" & y)) And Range("E" & y) > 0 Then Range("H" & y) = True
That will not fix cells that were numbers greater than 0 but later become something else.
 
Upvote 0
Solution
None of them are blank so all are greater than 0? I have to admit that it's not intuitive that the default for that comparison works that way.
What exactly are you trying to do? I only see 1 cell with a number and none of the rest are blank. Perhaps you want to only compare numbers? Then maybe
VBA Code:
If Rows(y).Hidden = False And Application.WorksheetFunction.IsNumber(Range("E" & y)) And Range("E" & y) > 0 Then Range("H" & y) = True
That will not fix cells that were numbers greater than 0 but later become something else.

Thank you, turns out I was on the right track before your response with:

VBA Code:
Sub test()
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    For y = 2 To lr
        If Rows(y).Hidden = False And IsNumber(Range("E" & y)) Then Range("H" & y) = True
    Next y
End Sub

I had forgot about Application.WorksheetFunction
 
Upvote 0
there is a specific VBA function that does the same thing: ISNUMERIC
 
Upvote 0
IsNumeric returns true if the value can be converted to a number data type. It doesn't mean it's a number data type, yes?

IsNumeric("12") is True
application.worksheetfunction.isnumber("12") returns False

Most cells had values that could end up being interpreted as strings so I suggested what I thought would be the least problematic. I'd still use IsNumber unless someone has a reason why not to do that.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

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