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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Put a "number" into a cell as a string 1

Status
Not open for further replies.

Gav42

Technical User
Sep 19, 2013
4
GB
I am trying to put the value that a user has entered in a combo box into a cell as a string using
....Formula = Str(ctrl.Value)
However the result is always a number (tested with the istext() function.

So how should I be doing it please?
 
hi,
Code:
With YourRange
   .NumberFormat = "@"
   .Value = Str(ctrl.Value)
End With


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
BTW, there is no IsText in VB!

Any string value that contains a the text for a numeric value, will ecaluate TRUE for IsNumeric(). So your num ber stored as a string will appear as numeric.

What are you attempting to accomplish with this technique?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
That worked - thanks!
Confused though as this is part of a process that adds a new row into my data table and starts by copying the last row in the table and clearing the contents of cells whose values are to be taken from my userform.
My seed row contains numeric strings initially so why can't I simply clear contents and assign a different string?
The seed cell is general format as proved by =CELL("format",C158) returning G
So I guess I need to work out how I achieved that in the first place!

 
If you're using Excel 2007+, have you considered using Structured Tables? This might preclude having to copy "the last row in the table and clearing the contents of cells whose values are to be taken from my userform."


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Some users are still on earlier versions, sadly. I seem to have actually solved my problem by pre-formatting the cells when the workbook is created. Not worked out how the numeric text gets in ok in the first place as that is part of a different process but problem solved (subject to backward compatibility checking)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top