

How to select a date range in the Excel date picker?įor selecting the date range, the user has to select the start and the end date of a process. The required year can be chosen and changed by clicking the up and down arrow buttons.The month can be chosen from the drop-down calendar by clicking on it.To go to the previous or the next month, click the arrow buttons placed at the left and the right side of the calendar.To enter a date in the selected cell, click on that date from the calendar of the required month.The drop-down calendar can be opened by clicking the down arrow.The working of the drop-down calendar is explained as follows: With the selection of a cell in column C, the drop-down calendar appears at the top right corner of the selected cell. read more to run when any cell is selected in column C.
#Inserting a drop down menu in excel 2016 code#
Note: The file should be saved with the extension “.xlsm.” This allows the VBA code VBA Code VBA code refers to a set of instructions written by the user in the Visual Basic Applications programming language on a Visual Basic Editor (VBE) to perform a specific task. #8 – At the end, we close the “If” statement. #7 – The “else” statement tells the compiler not to display the date picker when a cell other than that in column C is selected. It allows the value selected in the drop-down calendar to be displayed in the cell.LinkedCell = Target.Address #6 – This statement links the date picker with the target cell. This gets a reference to the cell in the next column.Left = Target.Offset(0, 1).Left read more” function with “0” as the row argument and “1” as the column argument.

Note: To get the reference of the next right cell, we use the “ Offset Offset The OFFSET function in excel returns the value of a cell or a range (of adjacent cells) which is a particular number of rows and columns from the reference point. This is the distance of the left border (of column D) from the extreme left of the worksheet. #5 – The next statement sets the “left” property of the date picker equal to that of the next right cell (of the selected cell). This means that it goes along with the upper border of the selected cell.Top = Target.Top #4 – The “top” property of the date picker is equal to the “top” property value of the selected cell. The “Intersect” function returns the address if a cell is selected in column C otherwise, the value is null. If any cell is selected in column C, only then does the date picker become visible. #3 – The “If” clause sets the following criteria: Note: We use the “with” operator so that we do not refer to “DTPicker1” again and again. #2 – The next statement sets the height and the width of the date picker to 20 points in Excel. The selected cell is sent to the sub procedure as “target.” Private Sub Worksheet_SelectionChange( ByVal Target As Range) #1 – The first statement tells the Excel compiler to run the code whenever a new cell is selected (i.e., the selection is changed). The explanation followed by the code within a block is given as follows: Visible = False End If End With End Sub Example 2 –The Code Explanation If Not Intersect(Target, Range("C:C")) Is Nothing Then Private Sub Worksheet_SelectionChange( ByVal Target As Range) Replace this existing code with the following code.

Step 10: In Visual Basic Editor, a code is already written.

