Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Date to nothing

Seeing another post, I noticed that you can format dates from cells:

i.e.

strDate = Format(Cells(selection, "A"), "dd/mm/yyyy")

That sounds idea for what I need. However, I guess I need to set the
variable strDate to a Date.

i.e.

Dim strDate as Date

That is great. But what I need to do is also have a condition that sets
the strDate variable to nothing if a condition is true

i.e.

If strCondition = "1" then

strDate = Format(Cells(selection, "A"), "dd/mm/yyyy")

Else

strDate = ""

End if

When I tried this, it said Type Mismatch. Obviously I need to wipe the
old date out from the variable stDate everytime I loop through. Is
there a way to set a date to nothing?

Any help is appreciated.


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Date to nothing

Andy,

The problem is that you are using Selection , which is a range, as a row
number, which is a number. Change

strDate = Format(Cells(selection, "A"), "dd/mm/yyyy")

to

strDate = Format(Cells(Selection.Row, "A"), "dd/mm/yyyy")


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"andyathome " wrote in message
...
Seeing another post, I noticed that you can format dates from cells:

i.e.

strDate = Format(Cells(selection, "A"), "dd/mm/yyyy")

That sounds idea for what I need. However, I guess I need to set the
variable strDate to a Date.

i.e.

Dim strDate as Date

That is great. But what I need to do is also have a condition that sets
the strDate variable to nothing if a condition is true

i.e.

If strCondition = "1" then

strDate = Format(Cells(selection, "A"), "dd/mm/yyyy")

Else

strDate = ""

End if

When I tried this, it said Type Mismatch. Obviously I need to wipe the
old date out from the variable stDate everytime I loop through. Is
there a way to set a date to nothing?

Any help is appreciated.


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Date to nothing

Try:

strDate = Empty


--

Julian Milano


"andyathome " wrote in message
...
Seeing another post, I noticed that you can format dates from cells:

i.e.

strDate = Format(Cells(selection, "A"), "dd/mm/yyyy")

That sounds idea for what I need. However, I guess I need to set the
variable strDate to a Date.

i.e.

Dim strDate as Date

That is great. But what I need to do is also have a condition that sets
the strDate variable to nothing if a condition is true

i.e.

If strCondition = "1" then

strDate = Format(Cells(selection, "A"), "dd/mm/yyyy")

Else

strDate = ""

End if

When I tried this, it said Type Mismatch. Obviously I need to wipe the
old date out from the variable stDate everytime I loop through. Is
there a way to set a date to nothing?

Any help is appreciated.


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Date to nothing

You need to decide what you want strDate to be. A text string or a Date. A
Date dataType is a number that can be displayed in a Date format.

"Dim strDate as Date" and "strDate = Format(yada yada)" won't work together.
nor will "Dim strDate as Date" and "strDate = ''".
Both are trying to assign a text string (the Format function returns a text
string) to a variable that you have specifically declared to be a number. A
classic case of TypeMismatch.

Change "Dim strDate as Date" to "Dim strDate as String" and the code you
posted will stop generating a TypeMismatch.

--
George Nicholson

Remove 'Junk' from return address.


"andyathome " wrote in message
...
Seeing another post, I noticed that you can format dates from cells:

i.e.

strDate = Format(Cells(selection, "A"), "dd/mm/yyyy")

That sounds idea for what I need. However, I guess I need to set the
variable strDate to a Date.

i.e.

Dim strDate as Date

That is great. But what I need to do is also have a condition that sets
the strDate variable to nothing if a condition is true

i.e.

If strCondition = "1" then

strDate = Format(Cells(selection, "A"), "dd/mm/yyyy")

Else

strDate = ""

End if

When I tried this, it said Type Mismatch. Obviously I need to wipe the
old date out from the variable stDate everytime I loop through. Is
there a way to set a date to nothing?

Any help is appreciated.


---
Message posted from http://www.ExcelForum.com/



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
Concatenate including a date so that the date appears as a date Zembu Excel Worksheet Functions 2 January 6th 10 06:09 PM
date in Cell to change colors if the date is beyond today's date Pete Elbert Excel Discussion (Misc queries) 2 June 6th 09 06:31 AM
Making a date go red, if date passes todays date. Jamie Excel Worksheet Functions 2 September 9th 08 02:14 PM
Report Date - Date Recv = Days Late, but how to rid completed date MS Questionnairess Excel Worksheet Functions 1 January 24th 07 11:05 PM
Date updates from worksheet to chart & changes date to a date series! Help!! Jayjg Charts and Charting in Excel 2 January 22nd 05 03:00 PM


All times are GMT +1. The time now is 10:44 AM.

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"