Text to Columns in Macro

JimM

Well-known Member
Joined
Nov 11, 2003
Messages
752
I'm trying to create a macro so that it converts a column of text to a number by using Text to Columns. I've created the macro using the recorder which worked fine but when I run the macro itself it's not updating the cells ie they still appear to be text. However if I then go into a cell, the cell descriptor shows it as General and if I F2 to edit it changes the cell to a value.
I've tried creating it as delimited and fixed width but still no joy
Any ideas of why the macro is not working as it should?

Thanks


The relevant code I'm using is

Sheets("DFC").Select
Columns("S:S").Select
Selection.TextToColumns Destination:=Range("S1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
If you are using VBA anyway try this:
VBA Code:
Sub ConvertValue()
    With Sheets("DFC")
        With Intersect(.Columns("A:A"), .UsedRange)
            .Value = .Value
        End With
    End With
End Sub
 
Upvote 0
What is the column formatting at the starting point ? Is it General at the start ? If so tell me what number formatting you want applied.
Can you provide an XL2BB of some of the data ?
 
Upvote 0
OK, not sure if this is a red herring but think there might be an invisible space at the end of each number. I've recorded a macro that mimics the F2 process and it's

Range("S4").Select
ActiveCell.FormulaR1C1 = "$55,983.60 "

See the empty space before the last "

I can't see the space when I go into the cell but is it likely that it's causing the issue
 
Upvote 0
What is the column formatting at the starting point ? Is it General at the start ? If so tell me what number formatting you want applied.
Can you provide an XL2BB of some of the data ?

Looks like start formatting is General, I need it to be a number or currency, basically something that I can sum up :)

Sorry can't upload as it's a work PC
 
Upvote 0
I'm in the UK so it should be £ and when I go into format cells, currency the symbol drop down box has a £ in it
 
Upvote 0
Sorry also just realised that when the column is being populated the source data has the £ attached, so when it's pasted into my spreadsheet it's pasting the £ as part of the cell contents - this may be why it's treating it as text ?
When I F2 in the cell it removes the leading £ but still displays it due to the formatting (hope that makes sense)
 
Upvote 0
I've fixed it! Instead of using Text to Columns I've simply used find and replace to remove the £ and my data is now working as I need it

Thanks for taking the time to respond though, it put me onto the solution!
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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