TextToColumns different in macro than outside of macro

jessemac_7

New Member
Joined
Feb 17, 2017
Messages
3
Hello everyone :)

I'm quite new to Excel macros but I've been introduced to a piece of work and I must say I'm completely stumped.

A bit of background first, not quite relevant to the problem but let's you know where I stand.

I've re-written an application that generates excel reports from a website and provides them to users. Some of these users have a special .xlsm that they use where they copy the contents of my reports into it, and it does some validation with other data.

After my re-write, the .xlsm files had to be updated with macros that could accept the new values and locations, everything works great except a single French report.

The values on this report are failing to validate unless if you highlight the column and run Data > Text to Columns > Fixed Width > General. The weird thing is, I can see no changes in the excel spreadsheet at all after doing this. However, I know changes have been made because Excel will ask me if I want to save before quitting, and the file size changes. Whatever this is doing, though not visible, allows the macros to run fine on it.

So I thought "simple enough" I'll record a macro of me doing it and have it inserted at the top of the macro that isn't working anymore. The macro showed up like this:
Code:
    Columns("C:C").Select
    Selection.TextToColumns Destination:=Range("C1"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(0, 1), TrailingMinusNumbers:=True

However! If you run the above macro, it does not do the same thing as running Text to Columns in Excel. The macro changes the way some of these numbers are displayed and just creates a weird mismatching of formatting
Ex:
236 490,59 becomes 236490.59
but
1 465 845,00 stays the same as 1 465 845,00

Because of this, adding that macro snippet to the top of the macro does not work and still fails validation.

I'm wondering if any can either
a) tell me what is happening when I'm pressing the "Text to Columns" button and nothing appears to change visually
but allows me to run my macro
b) suggest a way to update the macro snippet above so that it behaves in the same manor as the "Text to Columns" button

I have tried this in both Excel 2007 and Excel 2016, same results.

Sorry for the lengthy explanation, any assistance would be greatly appreciated!
Please let me know if you need any further details.
Thanks in advance!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
Which row does the data in column C start?

Does it make any difference if you make this simple change to the code?
Code:
  Columns("C:C").TextToColumns Destination:=Range("C1"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(0, 1), TrailingMinusNumbers:=True
 
Last edited:

jessemac_7

New Member
Joined
Feb 17, 2017
Messages
3
Which row does the data in column C start?

Does it make any difference if you make this simple change to the code?

Thanks for the quick Response Norie!

The row on which the data starts is row 11. Sadly, I've tried selecting only the specific data, and it still does the same thing when run through the macro:
Code:
    Range("C11", "C20").Select    Selection.TextToColumns Destination:=Range("C11"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(0, 1), TrailingMinusNumbers:=True

And thanks for the suggestion, I tried running your code snippet but sadly, the same issue occurred, the formatting gets all screwed up :(
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
How is the original data formatted?
 

jessemac_7

New Member
Joined
Feb 17, 2017
Messages
3
How is the original data formatted?
This is currently how the values are formatted originally:
SuiOXfq.png


Thanks!
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
What happens if rather than using Text to columns... you change the format of column C to what you want it to be?
 

Forum statistics

Threads
1,137,154
Messages
5,679,917
Members
419,862
Latest member
Bluewings666

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
Top