Passing a String in Array to Range as String

  • Thread starter Thread starter marston.gould
  • Start date Start date
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.
 
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
 
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
 

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

Back
Top