简体   繁体   中英

VBA: Code review

I am new to excel macro, but have basic understanding.

I am trying to find a max value from Sheet1, where I have the code but want to know how I get the same result if I run this code from any other sheets I have on my workbook.

Sub FindMaxDate()
Set Worksheet = Sheets("Sheet1")
Max_date = Application.WorksheetFunction.Max(Columns("A"))
MsgBox CDate(Max_date)
End Sub

For example: I have date filed on Sheet1.Range("A:A") and the max date available there is 01.01.2018 (Cod will give me the same value), but if I am on Sheet2 and run this code it will take value from Sheet2 and show me "12:00:00 AM".

Some one please help me to correct this code so that it will always show the max value from Sheet1 ( 01.01.2018 )

Hope you guys get my queston. Else please let me know.

Thank you

Sub FindMaxDate()
Set Worksheet = Sheets("Sheet1")
Max_date = Application.WorksheetFunction.Max(Worksheet.Columns("A"))
MsgBox CDate(Max_date)
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM