Use the following link to download the Excel Workbook seen in the videos below: Fruit Inventory Status
See it in Action!Watch this video to see this macro in action.
The CodeHere is the code for this macro. Make sure the following References are setup before running it: Visual Basic For Applications, Microsoft Excel 16.0 Object Library
'Leverage & Lean "Less Clicks, More Results" Sub FindLargestSmallestValue() ' Means that these variables are in use Dim CurrentMax As Double ' Dim CurrentMin As Double ' Dim LastColumnLetter As String ' Dim LastColumnNumber As Integer ' Dim LastRow As Integer ' Dim Max As Double ' Dim Min As Double ' Dim Rng As Range ' Dim Ws As Integer ' Ws = 1 Do Until Ws > Worksheets.Count 'Loop through every Worksheet] LastRow = Sheets(Ws).Cells(Rows.Count, 1).End(xlUp).Row 'Identify Last Row LastColumnNumber = Sheets(Ws).Cells(1, Columns.Count).End(xlToLeft).Column 'Identify Last Column Number LastColumnLetter = Replace(Sheets(Ws).Cells(1, LastColumnNumber).Address(True, False), "$1", "") 'Identify Last Column Letter Set Rng = Sheets(Ws).Range("A1:" & LastColumnLetter & LastRow) 'Set Range CurrentMin = Application.WorksheetFunction.Min(Rng) 'Worksheet Function MIN returns the Smallest value in a Range CurrentMax = Application.WorksheetFunction.Max(Rng) 'Worksheet Function MAX returns the Largest value in a Range If CurrentMax > Max Then Max = CurrentMax 'If Current Max found is Larger then Max set If Min > CurrentMin Then Min = CurrentMin 'If Current Min found is Smaller then Min set If Ws = 1 Then Min = CurrentMin 'Set Min from first Worksheet so initial 0 isn't returned at finish Ws = Ws + 1 Loop MsgBox "This Workbook " & ActiveWorkbook.Name & " has a Max of " & Max & " and Min of " & Min End Sub 'Stay Awesome!
Macro MondayHere is the Macro Monday video this macro was featured in. Watch this video to learn how to get the most out of this macro and start using it today!
CustomizationThese lines of code can be customized to personalize this macro.
20. Set Rng = Sheets(Ws).Range(“A1:” & LastColumnLetter & LastRow) ‘Set RangeDetails to Customize
23. If CurrentMax > Max Then Max = CurrentMax ‘If Current Max found is Larger then Max set Update the Current Max value if a new one is found.
24. If CurrentMin < Min Then Min = CurrentMin 'If Current Min found is Smaller then Min set Update the Current Min value if a new one is found.
25. If Ws = 1 Then Min = CurrentMin ‘Set Min from first Worksheet so initial 0 isn’t returned at finish Set the initial Current Min found on the first instance of the Rng.
29. MsgBox “This Workbook ” & ActiveWorkbook.Name & ” has a Max of ” & Max & ” and Min of ” & Min This is the MsgBox that will display once this macro finishes.
You can also call this Excel macro immediately when a Workbook opened by pasting this code into the ThisWorkbook portion of Visual Basic.
Sub Workbook_Open() 'Call MacroName Call FindLargestSmallestValue End Sub