VBA If statement

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Dear All,

I have two dates, where I'd like a message box to pop, if the dates are between this criteria.

Code:
    sDate1 = #10/1/2019#
    sDate2 = #9/30/2020#


How would I create the following?

Code:
 If date is between sDate1 & sDate2 Then
                                        
             MsgBox " Dates Within Range" 
   
End If

Thank you!
pinaceous
 
That msgbox no!
It is the msgbox that says "valid dates", I put it in post #17.
I didn't want to put the whole macro, but to avoid confusion, here it is:

VBA Code:
Sub test1()
  Dim wCount As Variant, c As Range
  Dim sDate1 As Date, sDate2 As Date
  sDate1 = #10/1/2019#
  sDate2 = #9/30/2020#
  wCount = WorksheetFunction.Count(Range("B6:B66"))
  If wCount = 0 Then
    MsgBox "NO Dates Listed"
  Else
    For Each c In Range("B6:B66")
      If c <> "" Then
        If IsDate(c) Then
          If sDate1 <= c And c <= sDate2 Then
            MsgBox "Valid Dates Listed"
            Exit For
          Else
          
          End If
        End If
      End If
    Next
  End If
End Sub
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,215,669
Messages
6,126,125
Members
449,293
Latest member
yallaire64

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