VBA Input Boxes

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
840
Hello,

I have the following code which starts with an input box that asks you to enter a period (which happens to be 4 digits long).

If this is not in the list "Items" then it will ask you for it again. If this is entered correctly then it will take you to a 2nd input box which asks you for a date in the format "yyyy-mm-dd". How would I put code, say Items2 which linked to a spreadsheet and if it was 1710 and the date 2017-08-20 was in a column B as below, then proceed, but if I entered 2017-08-23 following an entry of 1710, it would ask you for another date?

I hope the above is clear. Many thanks in advance.

1710 2017-08-20
1710 2017-08-21
1710 2017-08-22
1711 2017-08-23


Code:
Sub Clean_Data()


Dim myValue As Variant
Dim myValue2 As Variant
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim FP As String, FN As String
Dim Found As Boolean
Dim z As Byte
Dim Items() As String


Items = Split("1710,1711,1712,1713,1801,1802,1803,1804,1805,1806,1807,1808,1809,1810,1811,1812,1813,1901,1902,1903,1904,1905,1906,1907,1908,1909,1910,1911,1912,1913,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2101,2102,2103,2104,2105,2106,2107,2108,2109,2110,2111,2112,2113", ",")


Found = False
Do
myValue = InputBox("Enter the period, e.g. 1804")


    If StrPtr(myValue) = 0 Then Exit Sub
    For z = LBound(Items) To UBound(Items)
        If myValue = Items(z) Then Found = True
    Next
Loop While Not Found


Dim NoFile As Boolean
NoFiles = False


If myValue = "" Then


Exit Sub


Else


myValue2 = InputBox("Enter the date you wish to clean the data in format yyyy-mm-dd e.g. 2017-06-28")


If myValue2 = "" Then


Exit Sub


Else
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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