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" wrote:
> 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
>
>
>
> Karen53 wrote:
> >
> > 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)
> > --
> > Thanks for your help.
> > Karen53
>
> --
>
> Dave Peterson
>
|