ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Userform text box return date value? (https://www.excelbanter.com/excel-programming/368679-userform-text-box-return-date-value.html)

Matt[_39_]

Userform text box return date value?
 
I have a text box on a form and i'd like to be able to use it to enter
a date in the format mm/dd/yy and compare it to cells that have the
date format

If Not (form1.Date1.Value = "" And form1.Date2.Value = "") Then
For Each cell In Range(Cells(2, 1), _
Cells(Worksheets("Data").UsedRange.Rows.Count - 1, 1))
If Not (cell.Value = form1.Date1.Value And _
cell.Value <= form1.Date2.Value) Then
cell.EntireRow.Hidden = True
End If
Next cell
End If

currently, when excuting this code, even entering the dates in the
format mm/dd/yyyy causes all rows to be hidden

any help would be great


Tom Ogilvy

Userform text box return date value?
 
If Not (form1.Date1.Value = "" And form1.Date2.Value = "") Then
For Each cell In Range(Cells(2, 1), _
Cells(Worksheets("Data").UsedRange.Rows.Count - 1, 1))
If Not (cell.Value = cdate(form1.Date1.Value) And _
cell.Value <= cdate(form1.Date2.Value) ) Then
cell.EntireRow.Hidden = True
End If
Next cell
End If

--
Regards,
Tom Ogilvy



"Matt" wrote:

I have a text box on a form and i'd like to be able to use it to enter
a date in the format mm/dd/yy and compare it to cells that have the
date format

If Not (form1.Date1.Value = "" And form1.Date2.Value = "") Then
For Each cell In Range(Cells(2, 1), _
Cells(Worksheets("Data").UsedRange.Rows.Count - 1, 1))
If Not (cell.Value = form1.Date1.Value And _
cell.Value <= form1.Date2.Value) Then
cell.EntireRow.Hidden = True
End If
Next cell
End If

currently, when excuting this code, even entering the dates in the
format mm/dd/yyyy causes all rows to be hidden

any help would be great



Jim Thomlinson

Userform text box return date value?
 
Text boxes return text. That is just what they do. You can use IsDate and
CDate to determine if the text is a date and then convert it. The other
option would be to place a calendar control on your form instead of a text
box. Depending what the form is this can be a very effective way of getting
dates...
--
HTH...

Jim Thomlinson


"Matt" wrote:

I have a text box on a form and i'd like to be able to use it to enter
a date in the format mm/dd/yy and compare it to cells that have the
date format

If Not (form1.Date1.Value = "" And form1.Date2.Value = "") Then
For Each cell In Range(Cells(2, 1), _
Cells(Worksheets("Data").UsedRange.Rows.Count - 1, 1))
If Not (cell.Value = form1.Date1.Value And _
cell.Value <= form1.Date2.Value) Then
cell.EntireRow.Hidden = True
End If
Next cell
End If

currently, when excuting this code, even entering the dates in the
format mm/dd/yyyy causes all rows to be hidden

any help would be great



Matt[_39_]

Userform text box return date value?
 
i have tried this before, but foolish i forgot about the rest of the
form and was thinking that when all rows were hidden there was
something wrong with my process, but its actually functioning exactly
how one would expect.

Thanks, i doubt i would have realized that it was working before
without you posting exactly what i had previous tried



All times are GMT +1. The time now is 03:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com