VBA for validating data

Godwin117

Board Regular
Joined
Dec 19, 2019
Messages
68
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have this excel document that dates are entered in cells F12 and G12 to the last row, data validation works when someone enters the data, but the dates don't change. I would like to know if there is a vba I could use to validate those dates and have a message box that shows where the errors are located.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I am a bit confused by your question.
I think we need more information about your process.
What exactly is causing these errors?
 
Upvote 0
I have this excel document that dates are entered in cells F12 and G12 to the last row, data validation works when someone enters the data, but the dates don't change. I would like to know if there is a vba I could use to validate those dates and have a message box that shows where the errors are located.
Hello!

You need specific validation rules, list all the conditions. What cells or ranges data affect on what ?
 
Upvote 0
Hello!

You need specific validation rules, list all the conditions. What cells or ranges data affect on what ?
For Column "G12: last row of data in column A", if the date is < today, then the message pops up showing what row the invalid date is located.
For column "F12: last row of data in column A", if the date is > today, then the message pops up showing what row the invalid date is located.
For either column, if date is = today, then message pops up asking the user to verify that date is correct.
 
Upvote 0
What event should pop up message / messages? What should be result of closing these messages?
What rows contains dates?
What column is the longest?

Would you consider variant with conditional formatting?
 
Last edited:
Upvote 0
What event should pop up message / messages? What should be result of closing these messages?
What rows contains dates?
What column is the longest?

Would you consider variant with conditional formatting?
If the date is invalid, a message box should pop up with an ok button.
Closing the messages end the macro.
The dates are in variable rows, but if there arent dates then it is blank.
Column A is the longest and has every row filled with information.
I currently have a conditional formatting, I'm trying to limit the size of the file. It's about 105MB as of now.
 
Upvote 0
If the date is invalid, a message box should pop up with an ok button.
Closing the messages end the macro
If the document already has incorrect data, do you want msgbox pop up once at the file opening?

The dates are in variable rows, but if there arent dates then it is blank.
Column A is the longest and has every row filled with information.
Got it. G is the right column?


I currently have a conditional formatting, I'm trying to limit the size of the file. It's about 105MB as of now.
It could be a problem soon. Doesn't cleaning up a lot of stuff help?
 
Upvote 0
Yes that is actually a better idea, thank you. Then probably verify before saving the workbook.
Yes G is the required column as well as F, just different validations.
It really does, finally found out to get a macro to automatically put the formulas in that will he used. Having 50 sheets doesnt help either lol.
 
Upvote 0
I'm allowed myself to make two buttons instead of one. It's more convenient, i think. Paste this to ThisWorkbook module.
VBA Code:
Private Sub Workbook_Open()
Application.ScreenUpdating = False
On Error Resume Next

Dim iAF As Variant, iAG As Variant, iR&, lR&, d As Date: d = Date

lR = Cells(Rows.Count, 1).End(xlUp).Row
iAF = Range("F12:F" & lR).Value
    For iR = 1 To UBound(iAF)
            If iAF(iR, 1) > d Then
                Dim m As Integer, mp$, mt$
                mt = "Next?"
                mp = "Need to check Date in F" & iR& + 11
                    m = MsgBox(mp, 4 + 32, mt)
                        If m = 6 Then
                        Else
                            Exit Sub
                        End If
            End If
    Next
    
iAG = Range("G12:G" & lR).Value
    For iR = 1 To UBound(iAF)
            If iAG(iR, 1) < d Then
                mt = "Next?"
                mp = "Need to check Date in G" & iR& + 11
                    m = MsgBox(mp, 4 + 32, mt)
                        If m = 6 Then
                        Else
                            Exit Sub
                        End If
            End If
    Next

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Make shure F and G column cells' formate is Date only (without time).
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top