VBA .find selects values up to 0.5 when looking for 0

Andyatwork

Board Regular
Joined
Mar 29, 2010
Messages
94
Hey all,

I am trying to use Find to scan a column of (thousands of) values and when it finds a value = 0 to cut the entire row and boot it to a dump tab.
It works, but it is also selecting values up to 0.4999 and I want those to be left where they are.

My code;

Code:
Sub zeroShares()

'   Searches Share Balance column of Merged Leavers data set for value 0
'   and purges them to the Zero Shares tab

    Dim i As Long                   'counter
    Dim fndRng As Range             'found cell containing search term
    Dim lrow As Long, lcol As Long
    Dim zCount As Long
    
    zCount = 1
'   Check share balance column on data tab for any records showing zero shares
    With shData.Range("I:I")

            Application.StatusBar = "Removing holders with zero shares..."
            Set fndRng = .Find(what:="0", After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, searchdirection:=xlNext, _
                            MatchCase:=False)
      
            If Not fndRng Is Nothing Then
                Do
                    zCount = zCount + 1
                    fndRng.EntireRow.Cut ShZero.Range("A" & zCount)
                    Set fndRng = .FindNext(fndRng)
                Loop While Not fndRng Is Nothing
            End If
    End With
    
End Sub

I thought about making the search term a variable and defining it as NOT <> 0 but realised that was a super backwards way fo saying =0, but I want zero to be zero, not anything up to nearly 0.5.

I considered doing some data faffing;
Code:
If value < 0.5 AND > 0 then value = 0
sort of thing, but this .find is being run on potentially tens of thousands of rows of data and the whole project is slow enough already so I don't want to add another calculation.

Any tips on getting .Find to recognise 0 and only 0?

Many thanks,

Andy
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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