If date does not match in column then return popup issue

Darkcloud617

New Member
Joined
Sep 7, 2017
Messages
38
Hello. This forum is absolutely wonderful and I have learned so much- so Thank You All. I have one last code to finish a spreadsheet I have been working on. I am attempting to write a code that checks column B (which contains dates) and if all dates in that column do not match then it should return a popup saying so. Essentially Column B should all be the same date and this will act as error catcher if they all are not the same (even if one cell is different). This is help a pivot table from adding in other dates and changing the structure.

Code:
                            With Worksheets("Sheet1")


                            For i = 2 To .Cells(.Rows.Count, "B").End(xlUp).Row


                            If .Cells(i, "B").Value <> "B2" Then


                            MsgBox "Please make sure only one date is in Column B."
                            Exit For
                            End If
                            Next i
                            End With

For some reason it returns the popup everytime the macro is used, even if all the dates in column b are the same. I thought this code would essentially say 'if date is greater than or less than the date in B2 then use popup'. I am not quite sure what I am missing from this.

Thank you for any help you can provide.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try
Code:
If .Cells(i, "B").Value <> .Range("B2") Then
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,216,571
Messages
6,131,482
Members
449,653
Latest member
aurelius33

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