Hoppa till huvudinnehåll

Hur tar jag bort icke-numeriska tecken från celler i Excel?

Antag att du har ett kalkylblad med massor av sådan information ABCD4578124YUIOH, och du vill bara ta bort de icke-numeriska tecknen  ABCDYUIOH men behåll de numeriska tecknen i celler. Naturligtvis kan du ta bort dessa tecken en efter en, men just här kan du snabbt bli av med de icke-numeriska tecknen från celler enligt följande:

Ta bort icke-numeriska tecken med VBA-kod

Ett praktiskt verktyg för att ta bort icke-numeriska tecken med ett klick


Ta bort icke-numeriska tecken med VBA-kod

Gör så här för att ta bort icke-numeriska tecken från ett intervall med VBA-kod:

1. Klicka Utvecklare > Visual Basic att öppna Microsoft Visual Basic för applikationer fönster. I Microsoft Visual Basic för applikationer fönstret klickar Insert > Modulerna, och kopiera och klistra sedan in följande koder i modulen:

VBA: Ta bort alla icke-numeriska tecken

Sub RemoveNotNum()
'Updateby Extendoffice
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    xOut = ""
    For i = 1 To Len(Rng.Value)
        xTemp = Mid(Rng.Value, i, 1)
        If xTemp Like "[0-9]" Then
            xStr = xTemp
        Else
            xStr = ""
        End If
        xOut = xOut & xStr
    Next i
    Rng.Value = xOut
Next
End Sub

2. Klicka sedan på -knappen för att köra koden, i pop-up KutoolsforExcel välj ett intervall med de icke-numeriska tecknen du vill ta bort och klicka sedan på OK knapp. Se skärmdump:

doc ta bort icke-numeriska tecken 1 kopia

3. Sedan tas alla icke-numeriska tecken bort i det valda intervallet.

doc ta bort icke-numeriska tecken 2

Om siffrorna med decimaler kan du använda följande VBA:

Sub RemoveNotNum()
'Updateby Extendoffice
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    xOut = ""
    For i = 1 To Len(Rng.Value)
        xTemp = Mid(Rng.Value, i, 1)
        If xTemp Like "[0-9.]" Then
            xStr = xTemp
        Else
            xStr = ""
        End If
        xOut = xOut & xStr
    Next i
    Rng.Value = xOut
Next
End Sub

Du kan se resultaten enligt nedanstående skärmdump:

doc ta bort icke-numeriska tecken 3


Ett praktiskt verktyg för att ta bort icke-numeriska tecken med ett klick

För att ta bort icke-numeriska tecken i ett intervall, Kutools för ExcelÄr Ta bort tecken verktyget kan få det gjort med ett klick.

Kutools för Excel : med mer än 300 praktiska Excel-tillägg, gratis att prova utan begränsning på 30 dagar. 

När du har installerat Kutools för Excel, gör enligt nedan:

1. Markera det område du vill ta bort icke-numeriska tecken. Klick Kutools > text > Ta bort tecken.

doc ta bort icke-numeriska tecken 4

2. I Ta bort tecken dialogrutan, kolla på Icke-numerisk alternativet i Ta bort tecken och klicka sedan på OK or Ansök knapp. Och de icke-numeriska tecknen tas bort från urvalet omedelbart. Se skärmdump:

doc ta bort icke-numeriska tecken 5

Klicka för att ladda ner Kutools för Excel och gratis testversion nu!

För mer detaljerad information om Ta bort tecken av Kutools för Excel, besök Ta bort beskrivning av teckenfunktioner.


Demo: Ta bort numeriska, alfabetiska, icke-utskrivbara eller alfanumeriska tecken från celler

Kutools för Excel: med mer än 300 praktiska Excel-tillägg, gratis att prova utan begränsning på 30 dagar. Ladda ner och testa gratis nu!

Relaterade artiklar:

Bästa kontorsproduktivitetsverktyg

🤖 Kutools AI Aide: Revolutionera dataanalys baserat på: Intelligent utförande   |  Generera kod  |  Skapa anpassade formler  |  Analysera data och generera diagram  |  Anropa Kutools funktioner.
Populära funktioner: Hitta, markera eller identifiera dubbletter   |  Ta bort tomma rader   |  Kombinera kolumner eller celler utan att förlora data   |   Rund utan formel ...
Superuppslag: Flera kriterier VLookup    VLookup med flera värden  |   VSök över flera ark   |   Fuzzy Lookup ....
Avancerad rullgardinslista: Skapa snabbt en rullgardinslista   |  Beroende rullgardinslista   |  Flervals-rullgardinslista ....
Kolumnhanterare: Lägg till ett specifikt antal kolumner  |  Flytta kolumner  |  Växla synlighetsstatus för dolda kolumner  |  Jämför intervall och kolumner ...
Utvalda funktioner: Rutnätsfokus   |  Designvy   |   Stor formelbar    Arbetsbok & Bladhanterare   |  Resursbibliotek (Automatisk text)   |  Datumväljare   |  Kombinera arbetsblad   |  Kryptera/Dekryptera celler    Skicka e-postmeddelanden efter lista   |  Superfilter   |   Specialfilter (filtrera fet/kursiv/genomstruken...) ...
Topp 15 verktygssatser12 text verktyg (lägga till text, Ta bort tecken, ...)   |   50+ Diagram Typer (Gantt Chart, ...)   |   40+ Praktiskt Formler (Beräkna ålder baserat på födelsedag, ...)   |   19 Införande verktyg (Infoga QR-kod, Infoga bild från sökväg, ...)   |   12 Konvertering verktyg (Siffror till ord, Valutaväxling, ...)   |   7 Slå ihop och dela verktyg (Avancerade kombinera rader, Dela celler, ...)   |   ... och mer

Uppgradera dina Excel-färdigheter med Kutools för Excel och upplev effektivitet som aldrig förr. Kutools för Excel erbjuder över 300 avancerade funktioner för att öka produktiviteten och spara tid.  Klicka här för att få den funktion du behöver mest...

Beskrivning


Fliken Office ger ett flikgränssnitt till Office och gör ditt arbete mycket enklare

  • Aktivera flikredigering och läsning i Word, Excel, PowerPoint, Publisher, Access, Visio och Project.
  • Öppna och skapa flera dokument i nya flikar i samma fönster, snarare än i nya fönster.
  • Ökar din produktivitet med 50 % och minskar hundratals musklick för dig varje dag!
Comments (13)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
HI Thanks for the coding, i am getting the syntax error highlighted on For i = 1 To Len(Rng.Value) and the debug Sub RemoveNotNum() is highlighted in yellow.. kindly advice.
This comment was minimized by the moderator on the site
The VBA works great. I modified it to always work on a column, as shown:

For Each Cell In Range("B2:B" & ActiveSheet.UsedRange.Rows.Count)

xOut = ""

For i = 1 To Len(Cell.Value)

xTemp = Mid(Cell.Value, i, 1)

If xTemp Like "[0-9]" Then

xStr = xTemp

Else

xStr = ""

End If

xOut = xOut & xStr

Next i

Cell.Value = xOut

Next

I also used this to sort a column by the last digit, changing the last part to Cell.Value = Right(xOut, 1) then sorting it numerically.
This comment was minimized by the moderator on the site
Send me it on my email id
This comment was minimized by the moderator on the site
Hi, I want to use this macro but want to pre-define a range. Can you please let me know how to pre-define the range. Thanks, Samit
This comment was minimized by the moderator on the site
Just wanted to let you know that if the string starts with zero(s), or starts with letters, followed by zero(s), followed by the rest of the string this will remove all of the beginning zeroes. This is weird because it doesn't remove the zero(s) if they are between other non-zero numbers within the string, only if they start the string or are the first numbers after the initial letters in a string. Example. 0060100 would come out as 60100 PFF057726 would come out as 57726. Let me know if you have an explanation for this and can think of a solution. Thank you.
This comment was minimized by the moderator on the site
Thanx Guys for such a nice work. The script is awesome and it worked for. Keep it up guys.
This comment was minimized by the moderator on the site
Use this Formaula for replacing the existing character with the new one =SUBSTITUTE(text,old_text,new_text,[instance_num]) for ex-=SUBSTITUTE(TRIM(G1),"/","") Wish U all Happy Easter 2015
This comment was minimized by the moderator on the site
I received an error when I hit the > run button in the developer: Compile Error: Expected:end of statement and the word "non" in non-numeric is highlighted
This comment was minimized by the moderator on the site
Wow. that worked , exactly what I needed. Thanks,
This comment was minimized by the moderator on the site
Awesome Worked GREAT!!!!!!!!
This comment was minimized by the moderator on the site
wouldn't be better to replace the input-box method by just setting WorkRng like this: Set WorkRng = Intersect(ActiveSheet.UsedRange, Selection) that way if user select a entire column it wouldn't generate any error.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations