Number Stored as Text Issue

R

Raul

I'm using a routine to retreive data from a SQL Server database and then
output the results to a worksheet. MaterialTbl is a variant array.

The issue is I get a "Number stored as text" error when I use:

Set DestRange = Range(Worksheets(ThisSheet).Cells(3, 3), _
Worksheets(ThisSheet).Cells(UBound(MaterialTbl, 1), _
3 + UBound(MaterialTbl, 2) - 1))

DestRange.Value = MaterialTbl

But I don't get the error if I use:

For i = 0 To UBound(MaterialTbl, 1)
For j = 1 To UBound(MaterialTbl, 2)
Worksheets(ThisSheet).Cells(3+ i, 3 + j - 1).Value = MaterialTbl(i, j)
Next j
Next i

Why would I get an error with the first method and not get an error with the
latter?

Thanks in advance,
Raul
 
J

Jim Thomlinson

Without looking too closely at exactly what you are trying to do there is an
obvious mistake in the first code. Range() requires 1 argument and can take
an optional second argument. You have supplied 3 arguments. It has no idea
what to do with 3 arguments.
 
R

Raul

I'm pretty sure the range() is working and two arguments are being passed
(all open parentheses and close parentheses make it very messy).

The specified range is being populated, but I'm getting a green triangle in
the upper left corner of each cell flagging the "Number Stored as Text" error
when I use the range() method.

By the way I have used the range method in a number of other routines
without running into this issue.

Thanks,
Raul
 
J

Jim Thomlinson

Sorry about that...

What are the values of
UBound(MaterialTbl, 1)
3 + UBound(MaterialTbl, 2) - 1
 
J

Jim Thomlinson

Try...
with Worksheets(ThisSheet)
Set DestRange = .Range(.Cells(3, 3), _
.Cells(clng(UBound(MaterialTbl, 1)), _
3 + clng(UBound(MaterialTbl, 2)) - 1))
end with
 
R

Raul

No joy; still getting the green triangles in the upper left corner of each
cell.

I get the results without the green triangles when I use a for next loop to
write the array element to the appropriate cell in the worksheet.

The results in the MaterialTbl array are numbers but there is text in one
column. By the way, MaterialTbl is defined as variant. For some reason the
range method treats the all values in the array as text and the loop method
recognizes the diference between numbers and text.

Thanks,
Raul
 

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