VBA MINUTE Function

VBA MINUTE Function

Objective of the VBA Minute Function:

The VBA Minute Function is a built-in function in MS Excel. It has one input argument or parameter. It returns the two-digit number as Minute from the specified time. It returns a number from 00 to 59 (It has a leading zero where applicable). It is a ‘Data and Minute’ type function. Default format of the Minute function is ‘MM’. The VBA Minute Function can be used in either procedure or function in a VBA editor window in Excel. We can use the VBA Minute Function any number of times in any number of procedures or functions. In the following section we learn what is the syntax and parameters of the Minute function, where we can use this VBA Minute Function and real-time examples.

Table of Contents:

Syntax of VBA Minute Function

The syntax of the VBA Minute Function is

MINUTE(time_value)

Parameters or Arguments

There is one parameter or argument for the Minute function in VBA. That is nothing but ‘time_value’.
Where time_value is a time to generate number as Minute from the specified time. It returns a number from 00 to 59. It has leading zero where applicable.

Where we can apply or use the VBA Minute Function?

We can use this VBA Minute function in MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.

Example 1: Display current Minute on the screen

Here is a simple example of the Minute Function. This below example macro uses the Minute function and displays the two-digit Minute from the specified date. In this case specified time is current time.

'Display Current Minute on the screen
Sub VBA_Minute_Function_Example1()
    
    'Variable declaration
    Dim sCurrentMinute As Integer
    
    'Assign current Minute to variable
    sCurrentMinute = Minute(Time)
    MsgBox sCurrentMinute, vbInformation, "Current Minute"
    
End Sub 

In the above example ‘sCurrentMinute’ declared as an Integer data type. And Minute is a vba function, it returns two digit number (number from a 0 to 59) as Minute. This variable ‘sCurrentMinute’ now contains the two-digit Minute.
Output:
Here is the screen shot of first example output.
VBA MINUTE Function Example 1

 

Example 2: Display current Minute on the Worksheet

Here is another example of the VBA Minute Function. This below example macro uses the Minute function and displays the Minute from the specified time on the Worksheet named ‘VBAF1.Com’ in Range ‘B18’.

Sub VBA_Minute_Function_ Example2()
'Display Current Minute on the Worksheet
   
    'Variable declaration
    Dim dCurrentMinute As Date
    
    'Assign current Minute to variable
    sCurrentMinute = Now
    Sheets("VBAF1.com").Range("B18") = Minute(sCurrentMinute)
    
    'or
    'Sheets("VBAF1.com").Cells(18, 2) = Minute(sCurrentMinute)
    
End Sub
    

Output:
Here is the screen shot of second example output.
VBA MINUTE Function Example 2

 

Example 3: Display Medium Time on the screen using Format

Here is one more example with Minute Function. This below example macro uses the Time function and changes the format of the time. Finally, it displays the medium time from the specified time on the screen. Long time includes hours, minutes and the Am/PM indicator.

Sub VBA_Minute_Function_ Example3()
'Format and Display medium Time on the screen    
    'Variable declaration
    Dim sCurrentMinute As Date
    
    'Assign current Minute to variable
    sCurrentMinute = Time
    MsgBox Format(sCurrentMinute, "Medium Time"), vbInformation, "Current Medium Time"
    
End Sub

Output:
Here is the screen shot of third example output.
VBA MINUTE Function Example 3

Instructions

Here are the instructions to use the Minute function in Excel.

  1. Open an Excel workbook.
  2. Press Alt+F11 to open VBA Editor window.
  3. Go to Insert menu and click on module from the available options.
  4. Insert above specified macro example.
  5. Select code and click on ‘Run’ command or use Keyboard shortcut ‘F5’.
  6. Ex1-Output: It displays two-digit Minute on the screen.
  7. Ex2-Output: It displays two-digit Minute on the Worksheet in Rage B18.
  8. Ex3-Output: It displays medium time from the specified time on the screen.
  9. Note: Difference between first output and second output is format of the Minute.

Download File

Click on following link to download free example excel workbook to learn more about the Minute function.

VBA Minute Function Examples

List of VBA Functions:

Please click on below link to go back to see all List of VBA Functions.
List of VBA Functions

Leave a Comment

Your email address will not be published. Required fields are marked *