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
OK , if your first cell has data is A2 (if another cell change A2 at code to your cell Address), Test this code and you see result as message box.
then write here messagebox result.
VBA Code:
Sub Test11()
MsgBox Range("A2").Value & "##"
End sub
if you see a.m. again at the end of result also try this code:
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
With Range("B1:B" & Lr)
.Formula = "=iferror(left(A1,find("" "",A1) -1)-0.5,"""")"
.Value = .Value
End With
Range("B1:C" & Lr).NumberFormat = "h:mm:ss AM/PM"
For i = 2 To Lr
If j = 0 Then j = Range("B" & i).End(xlDown).Row
If Range("B" & j - 1).Value = "" Then
 j = j - 1
End If
If Range("B" & i) = Application.WorksheetFunction.Max(Range("B" & i & ":B" & j)) Then
Range("C" & i) = Range("B" & i)
 i = j
j = 0
End If
Next i
End Sub
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi Maabadi,

The prompt shows as follows (so no AM appears here):
 

Attachments

  • MrExcelPromptValue.png
    MrExcelPromptValue.png
    23.6 KB · Views: 11
Upvote 0
Please upload example file on google drive and insert link here (description at below). we have problem with google sheets.
 
Upvote 0
Hi Maabadi,

Excuse me for the delayed reaction. I have tried working out to upload the document, but every time I do, GoogleDrive just converts the sheet as if it were a Google Sheets file (where the data gets altered for some reason, to date-like data rather then entries in seconds) so thats very inconvenient as you are unable to look in to the file within Excel. I will try to see if I can get dummy numbers to work using your code anyway. I will let you know whether I could make sense of it eventually!
 
Upvote 0
Paste your Data at column F and after Running macro you see result at Column H.
TestPSD
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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