PDA

View Full Version : Solved: Force string array to return text, not numbers?



skulakowski
04-15-2005, 09:52 AM
List(q) is a string array so reading the number 2 into List(q) gives me the text 2. This is exactly what I want.

However, when I write List(q) back out into my spreadsheet, VBA gives me the number 2. This is not what I want.

Any ideas how I can force List(q) to return text strings to me and never numbers?


ReDim List(0 To j) As String
For q = 0 To j
List(q) = Cells(q, 1)
Next q

' do other stuff with List(q) but NEVER touch the intial entry

For q = 0 To j
ActiveCell.Offset(q, 0).Value = List(q)
'tried ActiveCell.Offset(q, 0).Formula = List(q) but .Formula didn't help me
Next q

Killian
04-15-2005, 10:14 AM
You've declared your array as an array of strings so List(q) can only return a string.
However, when the cell value is assigned, it automatically interprets it as a number, so you need to force the cell format in Excel'instead of ActiveCell.Offset(q, 0).Value = List(q)
With ActiveCell.Offset(q, 0)
.NumberFormat = "@"
.Value = List(q)
End With

skulakowski
04-15-2005, 11:33 AM
Cool. Thanks.