Passing a String in Array to Range as String

M

marston.gould

If I have an array that contains strings - some of which are numbers as
strings, why can't I write them to a range as a string?

For example if Array(1) = "000"

Why can't I say

Range("A1").Offset(1,1) = Array(1)

What I'm getting is 0 (without the leading 2 zeros) and when I do a
=IStext() test in the worksheet, I'm getting False.
 
A

Alan Beban

If I have an array that contains strings - some of which are numbers as
strings, why can't I write them to a range as a string?

For example if Array(1) = "000"

Why can't I say

Range("A1").Offset(1,1) = Array(1)

What I'm getting is 0 (without the leading 2 zeros) and when I do a
=IStext() test in the worksheet, I'm getting False.

The following seems to work:

Dim arr
arr = Array("000", "001", "002")
Range("A1").Offset(1, 1).NumberFormat = "@"
Range("A1").Offset(1, 1) = arr(1)

Alan Beban
 
N

Norman Jones

Hi Marston,

One way:

For i = LBound(Arr) To UBound(Arr)
With Range("A" & i + 1).Offset(1, 1)
.NumberFormat = "@"
.Value = Arr(i)
End With
Next i
 
Top