Check if date exists in entire Date column of Table4

JohnZ1156

Board Regular
Joined
Apr 10, 2021
Messages
160
Office Version
  1. 2021
Platform
  1. Windows
I have a vba script to check if a specific date exists in the current active cell, I would like it to check if an inputted date exists anywhere in the column.
I guess I'm looking for the "With Range(ActiveCell.Address)" to be the entire Date colmun in my Table4 table.

VBA Code:
    Dim var As Date

'Enter Date
    var = InputBox("Please enter the Date.", "Date", Default, XPos:=2880, YPos:=5760)
    Worksheets("Sheet1").Select
    Range("B15").Value = var

    Range("A11").End(xlDown).Select

[B]    With Range(ActiveCell.Address)[/B]
        If Not IsDate(.Value) Then
        MsgBox "No date"
        ActiveCell.Offset(1, 0).Select

        ElseIf .Value = var Then
        MsgBox ("Data entered " & var & " already exists.")

        ActiveCell.Offset(1, 0).Select
        Worksheets("Sheet2").Select
    Else
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
See if the following code fragment works for you:
VBA Code:
Dim rng As Range
Set rng = ActiveSheet.ListObjects("Table4").ListColumns("Date").Range. _
    Find(var, , xlValues, xlWhole, xlByRows, xlNext, False, False)
If rng Is Nothing Then
    MsgBox "No date"
Else
    MsgBox "Data entered " & var & " already exists."
End If
 
Upvote 0

Forum statistics

Threads
1,215,358
Messages
6,124,487
Members
449,165
Latest member
ChipDude83

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