djburnheim
Technical User
I'm trying to write a procedure that finds a maximum in a Range and then returns it and the value of the cell to the left of it. I can get the maximum no worries and I've been playing around trying to use the find function to get the cell it's in, then the offset property to reference the cell to the left of it but it never seems to find the value (see below). I'm wondering if there is another way I could do it.
***Code***
Dim CommentText As String
dRow = 1
dColumn = 3
'Find Maximum time from Sheets "Temp"
Sheets(1).Cells(dRow + 2, dColumn) = Application.WorksheetFunction.Max(Sheets("Temp"
.Range(Sheets("Temp"
.Cells(1, 2), Sheets("Temp"
.Cells(1000, 2)))
'Format time for find function
Longest = Format(Sheets(1).Cells(dRow + 2, dColumn), "hh:mm:ss"
'Search Sheets "Temp" for Longest Time
With Sheets("Temp"
.Range("B1:B1000"
Set mCell = .Find(Longest)
If Not mCell Is Nothing Then
CommentText = Format(mCell.Offset(0, -1), "H:MM:SS AMPM"
End If
End With
Any suggestions?
Thanks
Dave
***Code***
Dim CommentText As String
dRow = 1
dColumn = 3
'Find Maximum time from Sheets "Temp"
Sheets(1).Cells(dRow + 2, dColumn) = Application.WorksheetFunction.Max(Sheets("Temp"
'Format time for find function
Longest = Format(Sheets(1).Cells(dRow + 2, dColumn), "hh:mm:ss"
'Search Sheets "Temp" for Longest Time
With Sheets("Temp"
Set mCell = .Find(Longest)
If Not mCell Is Nothing Then
CommentText = Format(mCell.Offset(0, -1), "H:MM:SS AMPM"
End If
End With
Any suggestions?
Thanks
Dave