Conditional data cleanup

PSD

New Member
Joined
Sep 10, 2021
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have a question on how to implement a line of code, selecting a specific cell value (and deleting a different one).
What I mean by this is the following (see image):

I have a range of time data points in a single column (either empty or not, in time format).
Whenever there are two (or more) consecutive cells consisting data, I wish to ONLY keep the "highest" (longest) value, deleting the rest of the grouped values.

Does anyone have a suggestion on how to go about this?
 

Attachments

  • MrExcelexample2.png
    MrExcelexample2.png
    6.3 KB · Views: 33

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try this:
VBA Code:
Sub Test()
Dim i As Long, j As Long, Lr As Long, Mx As Double
Lr = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To Lr
If j = 0 Then
j = Range("A" & i).End(xlDown).Row
If Range("A" & j - 1).Value = "" Then j = j - 1
End If
If Range("A" & i) = Application.WorksheetFunction.Max(Range("A" & i & ":A" & j)) Then
Range("B" & i) = Range("A" & i)
i = j
j = 0
End If
Next i
End Sub
 
Upvote 0
Hi maabadi,

Thank you for the response.
I tried to add your proposed code using the VBA macro program, but I have to say I am quite inexperienced with this. It seems that when I run it, it only shows the first two entries and afterwards only blanks (see image).
Odds are that I am just not making it run correctly but this I simply do not know at this moment.

Thank you for the posed advice anyway, I will try to make it work in the meantime!
 

Attachments

  • MrExcelexample2.png
    MrExcelexample2.png
    8.1 KB · Views: 26
Upvote 0
Code works for me Correctly.
Please upload your Data file with XL2BB Add-in.
I don't know what is range of your data at image? Rows & Column Numbers.
 
Upvote 0
Hi Maabadi,

I have attached a range of data points and error times on which I would like to run your proposed macro. (2nd column)

I feel like the problem lies with me not being able to successfully use your proposed macro.
Now even when I run the code (View -> Macro -> Run Macro) it does not change anything in the worksheet.
Any suggestion on what I might be forgetting or doing wrong?

GP3109CartonPackerFaults.xlsm
H
8
Sheet2

GP3109CartonPackerFaults.xlsm
EF
1Column1Column2
200:31:2200:00:01
300:31:23 
400:31:4900:00:05
500:31:54 
601:19:4600:01:11
701:20:57 
801:35:1700:00:07
901:35:24 
1001:41:3500:00:07
1101:41:42 
1202:18:1100:01:16
1302:19:27 
1402:33:4600:00:39
1502:34:25 
1602:41:4000:00:29
1702:42:09 
1802:43:4600:00:14
1902:44:00 
2003:09:3500:13:22
2103:22:57 
2203:48:3400:00:53
2303:49:27 
2403:49:3800:00:05
2503:49:43 
2603:53:3000:00:36
2703:54:06 
2803:55:5300:01:00
2903:56:53 
3003:57:1800:00:56
3103:58:14 
3204:13:1700:00:57
3304:13:2000:01:42
3404:14:14 
3504:15:02 
3604:16:3500:01:06
3704:17:41 
3804:20:3100:01:14
3904:21:45 
4004:26:1300:01:50
4104:28:03 
4204:31:2100:00:14
4304:31:2300:00:03
4404:31:26 
4504:31:35 
4604:31:5000:00:04
4704:31:54 
4804:34:5100:00:04
4904:34:55 
5004:37:2300:01:44
5104:39:07 
5205:11:4000:00:41
5305:12:21 
5405:19:1800:00:08
5505:19:26 
5605:21:1800:00:08
5705:21:26 
5805:28:1100:00:04
5905:28:15 
6005:28:2300:00:06
6105:28:29 
6205:28:3900:00:51
6305:29:30 
6405:33:1300:00:07
6505:33:20 
6606:15:4500:00:11
6706:15:56 
6806:20:3500:00:09
6906:20:44 
7006:23:2700:00:09
7106:23:36 
7206:23:5400:00:09
7306:24:03 
7406:24:0900:00:16
7506:24:25 
7606:24:3100:01:09
7706:25:40 
7806:28:0400:00:08
7906:28:12 
8006:44:2900:00:33
8106:45:02 
8206:46:3200:00:53
8306:47:25 
8406:54:3700:00:14
8506:54:51 
8607:09:0900:00:29
8707:09:38 
8807:10:0500:00:11
8907:10:16 
9007:10:2600:00:16
9107:10:2800:00:00
Sheet2
Cell Formulas
RangeFormula
F2:F91F2=IF(C2=0,"",IFERROR(SUM(INDEX(FILTER(D3:E$20178,(B3:B$20178=B2)*(C3:C$20178=0)),1,))-SUM(D2:E2),"Open"))
 
Upvote 0
You should change column letters within code to your data column names.
Try this:
VBA Code:
Sub Test()
Dim i As Long, j As Long, Lr As Long, Mx As Double
Lr = Range("F" & Rows.Count).End(xlUp).Row
For i = 1 To Lr
If j = 0 Then
j = Range("F" & i).End(xlDown).Row
If Range("F" & j - 1).Value = "" Then j = j - 1
End If
If Range("F" & i) = Application.WorksheetFunction.Max(Range("F" & i & ":F" & j)) Then
Range("H" & i) = Range("F" & i)
i = j
j = 0
End If
Next i
End Sub
 
Upvote 0
Hi Maabadi,

That makes sense and is for sure one of the reasons why it did not work as intended.
However, trying to run the script with the correct column labelling did not necessarily do the trick.
Attached is a picture on where I have currently saved the macro, I feel like I am doing something wrong there. The labelling being for columns A and B is correct is that case (sheet 4). I ran and saved the macro after this. The script is also saved in Modules, under Modules 1.
Macro Mr Excel.png


Going towards the Excel sheet and running the macro from the View or Developer tabs does not show changes in the file.

Sorry for turning the original problem in to a sort of user experience trouble shoot problem, but I am curious as to why I seem unable to get a macro script running properly.
 
Upvote 0
You need to put the macro in a standard module, not a sheet module.
 
Upvote 0
Hi Fluff,

Thank you for the response.
I have removed the scripts from the separate sheet module, only having it saved under Modules in Module1. This did not solve the problem, or is this not what you meant as a standard module?
 
Upvote 0
Putting it in Module1 is fine. Was the sheet you wanted the macro to work on the active sheet when you ran it?
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

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