Same Data (date) Validation List for 2 cells; 1 cells to be greater than other cell

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,674
Office Version
365
Platform
Windows
Hi,

I have a named range [Range_Date] filled with dates Jan 2019 - Dec 2020, incrementing monthly.

On another sheet I have two cells with data validation for list with values [Range_Date], where one is the start date and other end date.

Is there a way to set data validation to ensure end date greater than start date as well as include drop down list?

TIA,
Jack
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,267
In this scenario...
Range_Date is on Sheet1 and is the Data Validation list for Sheet2 A1
Range_Date2 is on Sheet1 and is the Data Validation list for Sheet2 A2

To start, Range_Date and Range_Date2 can be the same list. The code will change Range_Date2.

To install the code below:
- Right-click on the sheet tab that has the DropDown lists (Sheet2)
- Select View Code from the pop-up context menu
- Paste the code from below in the Worksheet's code module
- Change the Sheet names and Data Validation cell addresses to suit

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Worksheet_Change([color=darkblue]ByVal[/color] Target [color=darkblue]As[/color] Range)
    [color=darkblue]Dim[/color] x [color=darkblue]As[/color] [color=darkblue]Variant[/color]
    [color=darkblue]If[/color] Target.Address(0, 0) = [B]"A1"[/B] [color=darkblue]Then[/color]
        Range("A2").Value = ""
        [color=darkblue]If[/color] Target <> [color=darkblue]Empty[/color] [color=darkblue]Then[/color]
            [color=darkblue]With[/color] [B]Sheets("Sheet1")[/B].Range("Range_Date")
                x = Application.Match(Target, .Cells, 0)
                [color=darkblue]If[/color] x < .Count [color=darkblue]Then[/color]
                    ThisWorkbook.Names.Add Name:="Range_Date2", RefersToR1C1:=.Cells(x + 1).Resize(.Count - x)
                [color=darkblue]Else[/color]
                    ThisWorkbook.Names.Add Name:="Range_Date2", RefersToR1C1:=""
                [color=darkblue]End[/color] [color=darkblue]If[/color]
            [color=darkblue]End[/color] [color=darkblue]With[/color]
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]End[/color] [color=darkblue]If[/color]
End [color=darkblue]Sub[/color]
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
45,283
Office Version
365
Platform
Windows
Would this be any use?
I have my Start Date Validation cell as A1 on Sheet2 and End Date DV cell as A2 on Sheet2.

On Sheet 1 I have the list of dates in A1:A24 & formulas as shown, copied down.

Excel Workbook
ABC
1Jan-19Jan-19 
2Feb-19Feb-19
3Mar-19Mar-19
4Apr-19Apr-19
5May-19May-19
6Jun-19Jun-19
7Jul-19Jul-19
8Aug-19Aug-19
9Sep-19Sep-19
10Oct-19Oct-19
11Nov-19Nov-19
12Dec-19Dec-19
13Jan-20Jan-20Jan-20
14Feb-20Feb-20Feb-20
15Mar-20Mar-20Mar-20
16Apr-20Apr-20Apr-20
17May-20May-20
18Jun-20Jun-20
19Jul-20Jul-20
20Aug-20Aug-20
21Sep-20Sep-20
22Oct-20Oct-20
23Nov-20Nov-20
24Dec-20Dec-20
Sheet1



I have then created 2 new named ranges (via the name manager on the Formulas ribbon tab) & used those in my data validation as shown.


Excel Workbook
AB
1Dec-19Start
2May-20End
Sheet2
#VALUE!
</td></tr></table></td></tr></table>
 

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,674
Office Version
365
Platform
Windows
Helper column d'oh (forehead palm!) and have absolutely no reason not to have a second date range!
@thanks Peter_Ss
 

Watch MrExcel Video

Forum statistics

Threads
1,102,849
Messages
5,489,239
Members
407,682
Latest member
gmb2521

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top