Macro to tell me when the highest sale happened

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
In column A i have date of sale
in column B I have time of sale (e.g. 13:00:00)
in column D i have number of sales

in cell G7 I have the highest sale of the week
i'd like a macro that when i click on the cell it tells me when this sale happened
so in simple terms i'd like this,

I click on cell G7,
it takes the value in G7 and looks down ColumnD to try find it,
if it finds it it brings up a message box saying
"Sale Happened on:"
"Then the Date it Happen and the time it happened"
e.g "12/04/2023 at 13:59:00"
please help if you can,
thanks
Tony
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
This assumes your date and time values are text:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cel As Range

If Not Target.Address = "$G$7" Then Exit Sub
Set cel = Cells.Find(What:=Range("G7"), After:=Range("D1"), LookAt:=xlWhole, LookIn:=xlFormulas, _
      SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
If Not cel Is Nothing Then
    MsgBox "Sale happened on " & cel.Offset(0, -3) & " at " & cel.Offset(0, -2)
End If
Set cel = Nothing

End Sub
 
Upvote 0
Solution
Glad I could help & thanks for the recognition.
 
Upvote 0

Forum statistics

Threads
1,215,217
Messages
6,123,675
Members
449,116
Latest member
HypnoFant

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