What wrong is the coding?

E

Eric

Does anyone have any suggestions on what wrong the coding is?

The variable temp is "1 " instead of "1", does anyone have any suggestions
on where the space comes from? The retrieved value should be returned "1"

Does anyone have any suggestions?
Thanks in advance for any suggestions
Eric

Set wsDate = Sheets("Date")
For lngRow = 2 To wsDate.Range("H1").Value

If Not SheetExists(wsDate.Range("A" & lngRow)) Then
Set ws = Sheets.Add(After:=Sheets(Sheets.Count))
ws.Name = wsDate.Range("A" & lngRow)
Else
temp = wsDate.Range("A" & lngRow).Text \ temp is "1 " instead of "1"

Set ws = Sheets(wsDate.Range("A" & lngRow).Text)
End If
 
E

Eric

There is error on following coding, which related to array out of range
something.
"1" sheet is existed, and I have tested this code "wsDate.Range("A" &
lngRow).Text", which return "1 " from temp.

This coding is not working.
Set ws = Sheets(wsDate.Range("A" & lngRow).Text)

Do you have any suggestions?
Thanks in advance for any suggestions
Eric
 
J

JLGWhiz

Probably the way the cell is formatted with a trailing space. Try it this
way.

temp =Trim( wsDate.Range("A" & lngRow).Text)
 
S

sali

JLGWhiz said:
Probably the way the cell is formatted with a trailing space. Try it this
way.

temp =Trim( wsDate.Range("A" & lngRow).Text)

probably yes,
..text -> returns cell's content as *displayed*, depending on custom format
as well
..value -> returns content as entered, and that is what is usualy needed,
just the *pure* value
 
J

JLGWhiz

Eric, Unless you have a sheet named "1", your code will fail when you try
to use:

Set ws = Sheets(wsDate.Range("A" & lngRow).Text)

Because conditions as you currently describe will result in the equivalent
code of:

Set ws = Sheets("1")

If there is no sheet named "1", then an error is produced for Subscript our
of Range.

If you are trying to use a value in Sheets(wsDate.Range("A" & lngRow) as an
index numer for Sheets( ), then it need to be numeric, not text.

Perhaps if you explain what you are trying to do, we could give better
assistance.
 

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