Date formated as text

K

Karen53

Hi,

I have cells which contain text. The cells are formated as text. However
the text in these cells can appear to be a date even though they are not, for
example 3-11-09. How do I keep the date formated as text error form
happening and erroring out my code? I need it to disregard that it looks
like a date and just treat it like text.

If MainPagepg.Range("BD" & Newrow - 1) = "" Then
ShNumber = Firstpg.Index
Else
AfterShName = MainPagepg.Range("BD" & Newrow - 1).Value
ShNumber = Sheets(AfterShName).Index
End If

CAMMaster.Copy After:=Sheets(ShNumber)
 
D

Dave Peterson

How did you declare AfterShName?

Dim AfterShName as String
or
Dim AfterShName as Variant 'or not declared???

If you used "as string", I would have guessed that your code would work.

But in either case, this may work (I didn't test it):
ShNumber = Sheets(cstr(AfterShName)).Index
 
K

Karen53

Hi Dave,

Yes, AfterShName was declared as a string. If the cell is in a general
format, Excel assumes it is a date. So, I changed the cell format to Text.
Then Excel indicates an error that the cell contains a date formated as text.

So far Cstr seems to be working. I'm still testing.

Thanks for your help!
--
Thanks for your help.
Karen53


Dave Peterson said:
How did you declare AfterShName?

Dim AfterShName as String
or
Dim AfterShName as Variant 'or not declared???

If you used "as string", I would have guessed that your code would work.

But in either case, this may work (I didn't test it):
ShNumber = Sheets(cstr(AfterShName)).Index
 

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

Top