Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA to stop excel outputting string as date

Status
Not open for further replies.

osx99

Technical User
Apr 9, 2003
250
GB
I have the following code

sub test()
string2 = "2/13 12L, Hill Forts Henry[9/2F]11-8"
Dim position As String
position = Trim(Left(Trim(string2), InStr(1, Trim(string2), " ", vbTextCompare)))
MsgBox (position)
Range("a1").Value = position
End sub

This should output 2/13 into cell a1 but excel converts it to a date 13-Feb

Is there a way to stop this happening?

Thanks,
os
 
Hi,

Excel is being "helpful" faq68-5827. You must write it as TEXT...
Code:
With Range("a1")
    .NumberFormat = "@"
    .Value = position
End With



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Format the cell as TEXT

[tt][blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top