VBA to Filter a value & Clear cells.

Revathi Kannan

New Member
Joined
Jan 27, 2012
Messages
23
I have a column which named as "Logic" wherein i need to filter the below 2 values from the said column and clear only the contents of the cell.

> 0
>00-01-1900 0:00:00

The major challenge is, i am not able to clear the cells of incorrect date format from the above point. Please assist.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try this
- assumes values are in column D starting at D2
- sets format in found cells to general

Code:
Sub ClearPositiveValues()
    Dim ws As Worksheet, cel As Range, eRng As Range, myStr As String
    Set ws = ActiveSheet
       
    For Each cel In ws.Range("[COLOR=#ff0000]D2[/COLOR]", ws.Range("[COLOR=#ff0000]D[/COLOR]" & Rows.Count).End(xlUp))    [I][COLOR=#006400]'amend to match your data[/COLOR][/I]
        If cel > 0 Then
            If myStr = "" Then myStr = cel.Address Else myStr = myStr & "," & cel.Address
        End If
    Next
    If Not myStr = vbNullString Then
        With ws.Range(myStr)
            .ClearContents
            .NumberFormat = "General"                                       [COLOR=#006400][I]'format as required[/I][/COLOR]
        End With
    End If
End Sub
 
Upvote 0
I tested the code before posting - it worked
I tested the code again, even on an empty sheet - it runs without failing
I think you have amended something incorrectly

Which cell contains header "Logic"?
What is the name of the sheet?

thanks
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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