Working with Date using macro

Babalola

New Member
Joined
Feb 26, 2018
Messages
13
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Occurence Time [/TD]
[TD]Recovery Time[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="class: xl84, width: 108"]2/25/201816:24[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]2/25/201818:14[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2/25/201813:54[/TD]
[TD]2/25/201815:24[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2/25/201810:09[/TD]
[TD]2/25/201811:24[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2/25/2018 7:24[/TD]
[TD]2/26/201816:24[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2/25/2018 11:24[/TD]
[TD]2/26/201812:24[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2/26/201816:24[/TD]
[TD]2/26/201816:24[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2/26/201816:24[/TD]
[TD]2/26/201816:24[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2/26/201816:24[/TD]
[TD]2/26/201816:24[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


if i have such table and i need to delete issues that occur on a particular day and recovers on same day e.g ( issues that started on 2/25/2018 7:24 and recover on 2/25/201818:14. leaving issues that started on 2/25/201818:14 and recovers on 2/26/2018 and also issues that started on 2/26/2018 and recovers on 2/26/2018 with the use of macro
****** id="cke_pastebin" style="position: absolute; top: 0px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]2/26/201816:24[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]2/26/201816:24[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]2/25/201818:14[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]2/25/201818:14[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]2/25/201818:14[/TD]
[/TR]
</tbody>[/TABLE]
</body>
 

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
You'd need to identify your range you're looking to clean up. Then, loop from the bottom to the top identifying which rows to delete. In VBA, you can use the DateDiff function to determine the days between the and resolved times.

I'm a bit confused on why you'd leave issues from Feb 26 that are resolved on the same day.

If we only keep rows where the two dates fall on different calendar days:
Code:
Sub RemoveSome()
Dim rng As Range
Dim i&


Set rng = [A2:B9]
For i = rng.Rows.Count To 1 Step -1
    If DateDiff("d", rng(i, 1), rng(i, 2)) = 0 Then rng(i, 1).EntireRow.Delete
Next i


End Sub
 
Upvote 0
tell whoever creates this report to create dates and not strings... also the formats are inconsistent... if things will be inconsistent your macro will have to check what situation it is dealing with and then do something different...your example will have to parse from strings for most of em then two it can use as a date... hard to write code for sloppy reports :)

these are dates... the rest are strings...

2/25/2018 7:24
2/25/2018 11:24
 
Last edited:
Upvote 0
tell whoever creates this report to create dates and not strings... also the formats are inconsistent... if things will be inconsistent your macro will have to check what situation it is dealing with and then do something different...your example will have to parse from strings for most of em then two it can use as a date... hard to write code for sloppy reports :)

these are dates... the rest are strings...

2/25/2018 7:24
2/25/2018 11:24

maybe how I copy , the report contains date... actually the Feb is just a sample
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
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