Date to nothing



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


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.


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


If strCondition = "1" then

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


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.



Bob Phillips


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")


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



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



George Nicholson

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.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Is Nothing 4
Nothing? 2
Not Nothing 5
if range=nothing then 2
If Not c Is Nothing Then 3
If nothing found ... 3
replacing , with nothing ? 2
Range is nothing 6