SOLVED

Alphanumeric Data

Copper Contributor

Hi Team Excel

 

I would like to see added a toggle switch to turn on or off stripping leading zero's from numeric text data when opened or imported into Excel.  Excel automatically strips leading zero's.  I have to use power query to retrieve data (for example, from comma delimited file) and manually back out the automatic formatting from the query.

 

Sometimes I want to retain leading zero's, sometimes I do not.  A toggle switch would help me control the Excel behavior.  Thanks for reading.

14 Replies

@PaulSpanbauer 

 

You need to use this VBA code:

 

 

Private Sub CommandButton1_Click()

If CommandButton1.Caption = "Remove Leading Zero" Then

Dim WorkRng As Range
On Error Resume Next
xTitleId = "Toggle Leading Zero"

Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Select The Range", xTitleId, WorkRng.Address, Type:=8)

WorkRng.NumberFormat = "General"
WorkRng.Value = WorkRng.Value

CommandButton1.Caption = "Add Leading Zero"

ElseIf CommandButton1.Caption = "Add Leading Zero" Then

xTitleId = "Toggle Leading Zero"

Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Select The Range", xTitleId, WorkRng.Address, Type:=8)

WorkRng.NumberFormat = "000000"

CommandButton1.Caption = "Remove Leading Zero"

End If

 

 

 

How it works:

  • From Developer TAB hit Design Mode & on left is INSERT,, just hit it.
  • Draw Command button from ActiveX controls.
  • Select & Right click the Command button & from menu find Properties.
  • Set the CAPTION as Remove Leading Zero.
  • Press ALT+F11 to open VB editor.
  • Then Copy & Paste this code as Standard Module.
  • Save the Workbook as Macro Enabled *.xlsm.
  • From Developer TAB, release the Design Mode.
  • Now hit the command button & Follow the instructions.

@Rajesh_Sinha 

This works on a range of data.  What I want is a toggle button in Excel configuration that turns off the standard Excel functionality of removing leading zeros from alphanumeric, imported data.

Leading ZEROs are an exceptionally used Cell format is not the default one also,,, so considering all that the VBA code I've suggested is best suitable and has liberty to work with the selected data range.

Using any programming method may spoil your data in another data range /Sheets,, and if you want to apply LEADING ZEROs as soon you open the Workbook,, in that case you need Workbook Open Event,, but remember then after you find Leading Zeros everywhere with all numeric Value !!
I do not need this for ranges already in Excel. I need it for importing data INTO Excel.

@PaulSpanbauer 

Consider example source data:

Segment 1 Segment2 Segment3 Amount
0000 0001 0002 10.00
0001 0100 0025 25.00
1000 0005 2500 10.00
3000 0000 0050 5.00

I want to import this data with the leading zero's in the segment columns intact.

Right now I have to use power query to import; then back out the automatic formatting step.

 

 

PaulSpanbauer_0-1618403484802.png

I have to go into "Transform Data" and back out the "Changed Type" step.

 

PaulSpanbauer_1-1618403575707.pngPaulSpanbauer_2-1618403607151.png

^^ Now I have the correct data.

 

What I want is a toggle switch in Excel that disables the automatic trimming of leading zero's from imported data.

 

I hope this makes sense.

 

Thanks, Paul Spanbauer

There was something ... believe in cell formatting

Custom formatting

0; -0 ;; @ that was for the zeros in front of it

0. ### that was, I think, for after the decimal point
Try it

I tried the first "0; -0 ;; @" formula and works very well with zeros before the comma.

Hope you can be helped with it.

Niklino
Could you please write ,, how you are IMPORTING data ,,, any third party tool or from DATA tab ,,, Get External Data,,,,, and let me say,,, after importing the data with leading zeros can't you use the VBA code I've suggested,,, don't you think is a quite useful one !!

How I import? Data tab on the ribbon --> Get Data --> From Text/CSV.

@Rajesh, @NikolinoDE your suggestions are fine as workarounds. What I am asking for is the ability to import the data with no workarounds. I want the imported data to be exactly as it appeared in the source without having to run a macro or format the cells.

This is the forum to suggest new functionality to the Microsoft development team is it not?

Thanks for the suggestions - but I can handle workarounds already. I want to import the data without workarounds.

@PaulSpanbauer 

If you have or would like to have a suggested solution,

you can put it in this area " https://excel.uservoice.com/ " as a suggestion.


We are just like you here, simple users offering help to other users.
Simple people who offer their help "selflessly" (as far as one could say this).


Please give your feedback there, so we can spend our time on the people who really need it.

 

Thank you for your understanding and time.

Nikolino

@NikolinoDE 

 

PaulSpanbauer_0-1618501209873.pngPaulSpanbauer_1-1618501296070.png

^^ This is how and why I ended up here for my ask.

best response confirmed by PaulSpanbauer (Copper Contributor)
Solution
I hope you don't misunderstand. It is good that you are here and of course you are welcome, as we are at microsoft in this forum.
I was concerned that the definition could be precise. As you described it at the beginning it was to be understood as if you needed a solution to your problem. But you would like to propose a solution / disseminate it. This could be better pointed out. Anyway, I would like to apologize from the start if I have worded anything wrong and accidentally offended you.

To put it briefly, please ask when and how much you want, there are no stupid questions, in the worst case you will get bad answers (some of them unintentionally from me).
Through questions I also learned what I know (or not) today.

I hope you continue to have fun with Excel .... the most beautiful invention since Schoko ... Uh, Microsoft.

Thank you for your understanding and patience

Nikolino
I know I don't know anything (Socrates)
Thanks Nikolino - I do appreciate all the responses - and I wasn't aware of the full scope of this forum when I posed my initial query. Your points are well taken.

Cheers, Paul
If there is any way to better label or otherwise characterize this post as a 'product enhancement request' (or similar) please advise. It's a shame that the UserVoice forum seems to have been shut down. Thanks again.
Thank you for your understanding,
I wish you continued joy, health, love and success in your life.
1 best response

Accepted Solutions
best response confirmed by PaulSpanbauer (Copper Contributor)
Solution
I hope you don't misunderstand. It is good that you are here and of course you are welcome, as we are at microsoft in this forum.
I was concerned that the definition could be precise. As you described it at the beginning it was to be understood as if you needed a solution to your problem. But you would like to propose a solution / disseminate it. This could be better pointed out. Anyway, I would like to apologize from the start if I have worded anything wrong and accidentally offended you.

To put it briefly, please ask when and how much you want, there are no stupid questions, in the worst case you will get bad answers (some of them unintentionally from me).
Through questions I also learned what I know (or not) today.

I hope you continue to have fun with Excel .... the most beautiful invention since Schoko ... Uh, Microsoft.

Thank you for your understanding and patience

Nikolino
I know I don't know anything (Socrates)

View solution in original post