Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:50:32+00:00 2026-06-09T23:50:32+00:00

I have an excel sheet (2003 and 2007) , in which I have got

  • 0

I have an excel sheet (2003 and 2007) , in which I have got two columns FromDate and ToDate of the type DateTime in mm/dd/yyyy format.

There can be “n” number of records in the excel sheet.

I want to apply a validation , such that value of ToDate column should always be greater then equal to value of FromDate column, when the file is saved. If this is not the case then an error message should be prompted

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:50:34+00:00Added an answer on June 9, 2026 at 11:50 pm

    EDIT: @brettdj made a great point – it may be the case that this already exists. If so, the following will show a message with each error (which will be super annoying if there are lots) and also debug.print it. Note that my setup here is the same as in the screenshots below. This will need to go into ThisWorkbook in the VBA Editor, and the code dropped into the BeforeSave event (this simply shows the errors and then continues to the save prompt):

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    
    Dim FromDate As Range
    ' Note that this assumes that the ToDate column has all values
    ' filled out. Otherwise it will stop short.
    Set FromDate = Range("B2:B" & Range("A2").End(xlDown).Row)
    
    ' Iterate each cell, checking the value next to it and showing
    ' an error if the ToDate is > FromDate (ignore blank FromDates)
    ErrorCount = 0
    For Each Cell In FromDate
      If Cell.Value < Cell.Offset(0, -1) And Cell.Value <> "" Then
        ' Handle your error however you want - this just prints
        MsgBox "Error in row " & Cell.Row
        Debug.Print Cell.Row
        ErrorCount = ErrorCount + 1
      End If
    Next Cell
    
    ' If we found any errors, cancel the save event
    If ErrorCount > 0 Then
      Cancel = True
    End If
    
    End Sub
    

    If you are entering data…

    Do you require it to use VBA? I only ask because you could do this without VBA using Data Validation:

    1.) Set up your data, select the ToDate column (don’t include the column header) and click Data->Data Validation on the Ribbon (I’m using Excel 2007), change the Allow drop-down to Date, change the Data field to greater than or equal to and enter =A2 for the Start Date field.

    enter image description here

    Now enter a few values into column B, including ones that aren’t ‘correct’ (this includes any non-date [a date as defined by the cell format, in my case mm/dd/yyyy] as well as one that is before the ToDate). You will receive an error message (which you can also adjust if needed). Happy to modify the answer if you do in fact need/prefer to use VBA.

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Excel sheet with two columns and I need to create new
I have an excel sheet with two columns of interest Year and Donations. The
I have 5 columns (SNO,Name,Phone,Address,Pin) in excel(2003/2007). Excel can have n no. of records.
I have a set od Excel (2003) sheets saved as .xlt format. Now ,how
I have an Excel sheet with two column, one is a number , and
Possible Duplicate: correlation matrix in r I have an excel sheet which has 700
I have created a xlt excel template which works fine in Excel 2007 under
Win-XP, Excel 2003 I have a range defined by a name, which is filled
I have a excel sheet which has around 5000 rows in it.I have used
I have an excel sheet with 8 rows and 4096 columns.I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.