I have 2 Macros I'm trying to combine into 1. And the first part runs fine but the 2nd one is not executing. Not sure what I'm missing. I even get the macro complete message at the end.
Rich (BB code):
Sub OneClickTest()
'
' OneClickTest Macro
'
'
Dim i As Long
Application.ScreenUpdating = False
For i = 1 To Range("H" & Rows.Count).End(3).Row
Select Case Left(Range("H" & i).Value, 1)
Case "6": Range("I" & i).Value = "Cellphone Repair"
Case "7": Range("I" & i).Value = "Metro PCS"
Case "8": Range("I" & i).Value = "Cricket"
Case Else
Select Case Range("H" & i).Value
Case "WR_BALAJI_OTHER", "WR_BALAJI_CRICKET"
Range("I" & i).Value = "Cricket"
End Select
End Select
Next
Application.ScreenUpdating = True
ActiveWorkbook.Worksheets("Scan_Record").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Scan_Record").Sort.SortFields.Add2 Key:= _
Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Scan_Record").Sort
.SetRange Range("$A$1").CurrentRegion
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("B:B").NumberFormat = "[$-en-US]m/d/yy h:mm AM/PM;@"
Dim ws As Worksheet
Dim lastRow As Long
Dim t As Long
Dim currentTime As Date
Dim cutoffTime As Date
' Set the worksheet
Set ws = ActiveWorkbook.Sheets("Scan_Record") ' Change "Sheet1" to your sheet name
ws.Sort.SortFields.Clear
ws.Sort.SortFields.Add2 Key:= _
Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
'With ws.Sort
With ws.Sort
.SetRange ws.Range("$A$1").CurrentRegion
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ws.Columns("B:B").NumberFormat = "[$-en-US]m/d/yy h:mm AM/PM;@" ' XXX Not sure you need this
' Find the last row with data in column B
lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
' Get the current date and time
currentTime = Now
' Set the cutoff time for the current day at 6:50 AM
cutoffTime = DateValue(currentTime) + TimeValue("06:50:00")
' Loop from the last row to the first row (bottom-up)
Application.ScreenUpdating = False
For t = lastRow To 1 Step -1
' Check if the timestamp in column A is before the cutoff time
If IsDate(ws.Cells(i, 2).Value) Then
If ws.Cells(i, 2).Value < cutoffTime Then
' Delete the row if the condition is met
ws.Rows(i).Delete
End If
End If
Next t
Application.ScreenUpdating = True
MsgBox "Macro complete!"
End Sub