Evaluate column and replace existing values

SamPaulRoger

New Member
Joined
Jul 28, 2018
Messages
12
Hi,

I am trying to have a macro evaluate column D which has dates listed, however, several in which are 1/0/1900 which I want to replace with nothing. Does anyone have any suggestions?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
**Bump**

I have worked out this much, however, when I run the script, it lists false through the whole column, I would like it to replace anything that equal's the "12:00:00 AM" value listed, however, leave the other dates listed. Any thoughts?

Code:
Sub Clear_Dates()
    Dim lRow As Long
    lRow = Sheet13.Cells(Rows.Count, "D").End(xlUp).Row
    Sheet13.Range("D2:D" & lRow).Value = Sheet13.Evaluate("IF(D2:D" & lRow & "=""12:00:00 AM"","""")")
End Sub

Sheet13 before

[TABLE="width: 150"]
<tbody>[TR]
[TD]Dates[/TD]
[/TR]
[TR]
[TD]7/30/2018[/TD]
[/TR]
[TR]
[TD]1/0/1900[/TD]
[/TR]
[TR]
[TD]8/2/2018[/TD]
[/TR]
</tbody>[/TABLE]

Sheet13 after (The Goal)

[TABLE="width: 150"]
<tbody>[TR]
[TD]Dates[/TD]
[/TR]
[TR]
[TD]7/30/18[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]8/2/2018[/TD]
[/TR]
</tbody>[/TABLE]


Sheet13 after (with current code above)

[TABLE="width: 150"]
<tbody>[TR]
[TD]Dates[/TD]
[/TR]
[TR]
[TD]False[/TD]
[/TR]
[TR]
[TD]False[/TD]
[/TR]
[TR]
[TD]False[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Hi sorry to say so, this quite basic question, you could use google. Date is just a number. Time is decimal.


Code:
Sub Clear_Dates()    
    Dim lRow, i As Long
    lRow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
     
    For i = 2 To lRow
        If (Cells(i, "A").Value) < 1 Then ' -- you can use this too, it is the same ---   < DateValue("1 Jan 1900") Then
            Cells(i, "A").Value = Null
        End If
        
    Next i
End Sub
 
Last edited:
Upvote 0
How about simply highlighting column D, and doing a Find/Replace, replacing "1/0/1900" with nothing, and then selecting "Replace All"?
 
Upvote 0
Does this work for you...
Code:
[table="width: 500"]
[tr]
	[td]Sub ClearDateZeroCells()
  Columns("A").Replace "1/0/1900", "", xlWhole, , , , False, False
End Sub[/td]
[/tr]
[/table]
Note: You can do this manually using Excel's Replace dialog box.
 
Last edited:
Upvote 0
Does this work for you...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub ClearDateZeroCells()
  Columns("A").Replace "1/0/1900", "", xlWhole, , , , False, False
End Sub[/TD]
[/TR]
</tbody>[/TABLE]
Note: You can do this manually using Excel's Replace dialog box.


Thank you Rick

Exactly what I was looking for, This processes 120,000 rows in a split second and I do not have to worry about formulas being deleted or providing extra steps to anyone else who have far less experience than what I do. I Appreciate the help
 
Upvote 0
Note: You can do this manually using Excel's Replace dialog box.
Yep, that is what I suggested right before Rick's reply. ;)

Note that Rick's code is just using VBA to do the same thing as doing it manually.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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