ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Passing a String in Array to Range as String (https://www.excelbanter.com/excel-programming/308572-passing-string-array-range-string.html)

[email protected]

Passing a String in Array to Range as String
 
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.


Alan Beban[_2_]

Passing a String in Array to Range as String
 
wrote:

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

Norman Jones

Passing a String in Array to Range as String
 
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

---
Regards,
Norman



" wrote in message
...
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.





All times are GMT +1. The time now is 09:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com