VBA Advice

purceld2

Well-known Member
Joined
Aug 18, 2005
Messages
586
Office Version
  1. 2013
Platform
  1. Windows
Hi

I have found this bit of VBA code(Below) which does what I require, but when it finds the latest date I would like to retrieve a extra bit of data from the same line.

Could somebody point me in the right direction please?

Rich (BB code):
Sub LastDate()
Dim Max_date As Date
Max_date = Application.WorksheetFunction.Max(Range("C3:C36"))
MsgBox Max_date
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You might consider the following...

VBA Code:
Sub LastDate()
Dim Max_date As Date
Dim RowNo As Long

Max_date = Application.WorksheetFunction.Max(Range("C3:C36"))
RowNo = Application.Match(CLng(Max_date), ActiveSheet.Range("C1:C36"), 0)
MsgBox "Max Date: " & Max_date & vbCrLf & _
    "Row No: " & RowNo & vbCrLf & _
    Cells(RowNo, 4)  '<----Change column number to match your "extra bit of data"
End Sub

Cheers,

Tony
 
Upvote 0
The way i would do that is like this:
VBA Code:
Sub test()
inarr = Range("c1:c36") ' Note I am starting the ragne at row 1 onot row 3 this is deliberate
max_date = 0
Maxi = 0
For i = 3 To UBound(inarr, 1) ' this starts the check on row 3
 If inarr(i, 1) > max_date Then
  max_date = inarr(i, 1)
  Maxi = i
 End If
Next i
ta = Range(Cells(Maxi, 1), Cells(Maxi, 1))
MsgBox (max_date & " this is on row " & Maxi)
MsgBox (" the value in column A on this row is " & ta)
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,824
Members
449,470
Latest member
Subhash Chand

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