delete entire row with condition (simple but failed)

auzanoo

Board Regular
Joined
Jan 6, 2020
Messages
63
Office Version
  1. 2007
Platform
  1. Windows
dear expert,

i have a data and code, but it's failed.

from this:
GOPI09:29-12:00
TOPIK TERKINI10:26-10:27
TOPIK TERKINI11:45-11:47
BEPANNAH(R)12:00-14:00


should be this:
GOPI09:29-12:00
BEPANNAH(R)12:00-14:00

so, the time should continue from one to another one.

but, the result is like this:
GOPI09:29-12:00
TOPIK TERKINI11:45-11:47



this is my code,
VBA Code:
Sub DeleteRowswithSpecificValue()

Blank = Range("A1", Range("A1").End(xlDown)).Rows.Count

For i = 1 To Blank
If Right(Cells(i, 2),5) <> Left(Cells(i+1, 2),5) Then
Cells(i+1, 2).EntireRow.Delete

End If
Next i
End Sub

and i want to add exceptional:
if the time is not so far (around 1 or 2 minutes), then dont delete the row.

for example,
from this:
GOPI09:29-12:00
TOPIK TERKINI10:26-10:27
TOPIK TERKINI11:45-11:47
BEPANNAH(R)12:02-14:00


to this:
GOPI09:29-12:00
BEPANNAH(R)12:02-14:00


i dont know what to do with this one.

thanks in advance!
 
Something like this
T = Abs(DateDiff("n", Right(Replace(Cells(i, 2), ".", ":"), 5), Left(Replace(Cells(i + 1, 2), ".", ":"), 5)))
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Something like this
T = Abs(DateDiff("n", Right(Replace(Cells(i, 2), ".", ":"), 5), Left(Replace(Cells(i + 1, 2), ".", ":"), 5)))
sorryyy but, that's not the problem.

i mean, the code works for 00:00 to 24:00 format,
but my data format is 02:00 to 26:00.

i think maybe it has to be subtract with 02:00 (2 hours) first, then do the calculation.

i tried with
Excel Formula:
 - TimeSerial (2,0,0)
and something else, but its not working
 
Upvote 0
sorryyy but, that's not the problem.

i mean, the code works for 00:00 to 24:00 format,
but my data format is 02:00 to 26:00.

i think maybe it has to be subtract with 02:00 (2 hours) first, then do the calculation.

i tried with
Excel Formula:
 - TimeSerial (2,0,0)
and something else, but its not working
What is 26:00? Just keep adding time from starting time?
 
Upvote 0
I'm not going to get stuck into the date problem, but just want to call out that you may want to pay attention to Mark's suggestion to test this where 3 consecutive rows meet the delete condition, and to heed his advice to loop backwards rather than forwards.
 
Upvote 0
What is 26:00? Just keep adding time from starting time?

soo, the actual data is like this
A102:00-02:09
A202:09-02:30
A302:30-03:45
A403:45-04:30
A504:30-04:59
A604:59-06:22
A706:22-08:00
A808:00-09:17
A909:17-09:49
A1009:49-10:49
A1110:49-12:21
A1211:54-11:56
A1312:21-14:54
A1414:19-14:20
A1514:54-16:26
A1616:26-18:29
A1718:29-20:29
A1820:29-23:11
A1923:11-24:38
A2024:38-25:39
A2125:09-25:39
A2225:39-25:59


it is start from 02:00, and end with 25:59.

I'm not going to get stuck into the date problem, but just want to call out that you may want to pay attention to Mark's suggestion to test this where 3 consecutive rows meet the delete condition, and to heed his advice to loop backwards rather than forwards.

nooo there is no other problem except the date
 
Upvote 0
soo, the actual data is like this
A102:00-02:09
A202:09-02:30
A302:30-03:45
A403:45-04:30
A504:30-04:59
A604:59-06:22
A706:22-08:00
A808:00-09:17
A909:17-09:49
A1009:49-10:49
A1110:49-12:21
A1211:54-11:56
A1312:21-14:54
A1414:19-14:20
A1514:54-16:26
A1616:26-18:29
A1718:29-20:29
A1820:29-23:11
A1923:11-24:38
A2024:38-25:39
A2125:09-25:39
A2225:39-25:59


it is start from 02:00, and end with 25:59.



nooo there is no other problem except the date
Looks like minus 2 to offset the hour like you thought is the solution since it will not affect minute.
 
Upvote 0
I'm not going to get stuck into the date problem, but just want to call out that you may want to pay attention to Mark's suggestion to test this where 3 consecutive rows meet the delete condition, and to heed his advice to loop backwards rather than forwards.
I think this is something like comparing difference progressively to the next one ignoring the deleted data. I have no idea on the purpose ?
 
Upvote 0

Forum statistics

Threads
1,216,091
Messages
6,128,775
Members
449,468
Latest member
AGreen17

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