Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Compare Date in Cell VS a Variable Date to Hide Row

I am trying to compare a date in a cell format "mm/dd/yyyy" against a date
which had been input into a userform [same format] to ultimately hide a row.

When I use the following code all rows are hidden.
"StartDate" is the variable from the UserForm
[Public StartDate As Date]

Range("D2").Select
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
' Insert your code here.
If ActiveCell.Value StartDate Then Selection.EntireRow.Hidden = True
Else
ActiveCell.Offset(1, 0).Select
Loop

If I convert the "D" column to the "Number" format and compare against the
number format date for "StartDate" the macro works. Where am I formating
incorrectly? Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Compare Date in Cell VS a Variable Date to Hide Row

You can try it this way:

Range("D2").Select
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
' Insert your code here.
If ActiveCell.Value2 clng(StartDate) Then ActiveCell.EntireRow.Hidden
= True
ActiveCell.Offset(1, 0).Select
Loop

--
Regards,
Tom Ogilvy

"JimI" wrote in message
...
I am trying to compare a date in a cell format "mm/dd/yyyy" against a date
which had been input into a userform [same format] to ultimately hide a

row.

When I use the following code all rows are hidden.
"StartDate" is the variable from the UserForm
[Public StartDate As Date]

Range("D2").Select
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
' Insert your code here.
If ActiveCell.Value StartDate Then Selection.EntireRow.Hidden = True
Else
ActiveCell.Offset(1, 0).Select
Loop

If I convert the "D" column to the "Number" format and compare against the
number format date for "StartDate" the macro works. Where am I formating
incorrectly? Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Compare Date in Cell VS a Variable Date to Hide Row

Thank you Tom,

I think that I have realized that I am not populating the StartDate variable
with the date from the userform. I have tried to define "Public StartDate
as Date" and am picking it up from the Date1 variable box in the Userform.
When I use MsgBox for StartDate and Date1 after I exit Userform I get no data
so I am not filling the variable. I have used UserForm in the past so I am
going to have to work on this one. Thanks for your help.

"Tom Ogilvy" wrote:

You can try it this way:

Range("D2").Select
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
' Insert your code here.
If ActiveCell.Value2 clng(StartDate) Then ActiveCell.EntireRow.Hidden
= True
ActiveCell.Offset(1, 0).Select
Loop

--
Regards,
Tom Ogilvy

"JimI" wrote in message
...
I am trying to compare a date in a cell format "mm/dd/yyyy" against a date
which had been input into a userform [same format] to ultimately hide a

row.

When I use the following code all rows are hidden.
"StartDate" is the variable from the UserForm
[Public StartDate As Date]

Range("D2").Select
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
' Insert your code here.
If ActiveCell.Value StartDate Then Selection.EntireRow.Hidden = True
Else
ActiveCell.Offset(1, 0).Select
Loop

If I convert the "D" column to the "Number" format and compare against the
number format date for "StartDate" the macro works. Where am I formating
incorrectly? Thanks




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Compare Date in Cell VS a Variable Date to Hide Row

when you unload the userform, the textbox is cleared. You need to set the
StartDate in the code before you unload the userform.

--
Regards,
Tom Ogilvy

"JimI" wrote in message
...
Thank you Tom,

I think that I have realized that I am not populating the StartDate

variable
with the date from the userform. I have tried to define "Public

StartDate
as Date" and am picking it up from the Date1 variable box in the Userform.
When I use MsgBox for StartDate and Date1 after I exit Userform I get no

data
so I am not filling the variable. I have used UserForm in the past so I

am
going to have to work on this one. Thanks for your help.

"Tom Ogilvy" wrote:

You can try it this way:

Range("D2").Select
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
' Insert your code here.
If ActiveCell.Value2 clng(StartDate) Then

ActiveCell.EntireRow.Hidden
= True
ActiveCell.Offset(1, 0).Select
Loop

--
Regards,
Tom Ogilvy

"JimI" wrote in message
...
I am trying to compare a date in a cell format "mm/dd/yyyy" against a

date
which had been input into a userform [same format] to ultimately hide

a
row.

When I use the following code all rows are hidden.
"StartDate" is the variable from the UserForm
[Public StartDate As Date]

Range("D2").Select
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
' Insert your code here.
If ActiveCell.Value StartDate Then Selection.EntireRow.Hidden =

True
Else
ActiveCell.Offset(1, 0).Select
Loop

If I convert the "D" column to the "Number" format and compare against

the
number format date for "StartDate" the macro works. Where am I

formating
incorrectly? Thanks






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How capture a date variable within a text cell? Capture a variable date & use with text[_2_] Excel Discussion (Misc queries) 4 November 28th 08 02:34 AM
How to compare a cell containing a date in sumif criteria Retired Nick Excel Worksheet Functions 5 June 13th 08 03:09 PM
Compare dates (one cell not in date format) craigcsb Excel Discussion (Misc queries) 5 June 28th 05 05:07 PM
How do I add a date formula to a cell but hide the contents with . Emzy Wemzy Excel Discussion (Misc queries) 2 December 12th 04 01:48 PM
calc constant date from variable date & return with ability to rn. SusieQ'sQuest Excel Worksheet Functions 1 November 9th 04 08:51 PM


All times are GMT +1. The time now is 04:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"