Forum Discussion
PaulSpanbauer
Apr 07, 2021Copper Contributor
Alphanumeric Data
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 z...
- Apr 15, 2021I 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)
Rajesh_Sinha
Apr 07, 2021Iron Contributor
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.
- PaulSpanbauerApr 13, 2021Copper Contributor
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.
- Rajesh_SinhaApr 14, 2021Iron ContributorLeading 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 !!- PaulSpanbauerApr 14, 2021Copper ContributorI do not need this for ranges already in Excel. I need it for importing data INTO Excel.