Coerce Number To String

goss

Active Member
Joined
Feb 2, 2004
Messages
372
Hi all,

Using Excel 2010

I would like to coerce all values in a column to strings (text) as some records are numbers and some are mix of number and alpha characters

I would like them all as strings before export to .csv

Here is my snippet which does not appear to work
Numbers are still number and are naturally right-justified and/or formatted as 5.51538E+11

Code:
With ws
Set rng = .Range("H1:H" & lngRows)
For Each C in rng
C.Value = CStr(C.Value)
Next C
End With
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You could use the Text to Columns feature to convert the entire column to text.

  • Select Column H
  • Select from the menu Data\ Text to Columns
    • Step 1: Fixed Width, Next
    • Step 2: Next
    • Step 3: Column Data Format=Text, Finish
 
Upvote 0
Thanks

Here is my final code, probably not the most esoteric, but it gets the job done.
It has the added functionality of ensuring all alpha charcters are Upper Case

Code:
strInvFormula = "=UPPER(H1)"
With wsData
Set rngInvText = .Range("M1:M" & lngRows)
rngInvText.Copy
.Range("H1").pasteSpecial(xlPasteValuesAndNumberFormats)
rngInvText.ClearContents
End With
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,628
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top