ไปยังเนื้อหาหลัก

วิธีลบอักขระที่ไม่ใช่ตัวเลขออกจากเซลล์ใน Excel

สมมติว่าคุณมีแผ่นงานที่มีข้อมูลจำนวนมาก ABCD4578124YUIOHและคุณต้องการลบเฉพาะอักขระที่ไม่ใช่ตัวเลขเท่านั้น  ABCDYUIOH แต่เก็บอักขระตัวเลขไว้ในเซลล์ แน่นอนคุณสามารถลบอักขระเหล่านั้นได้ทีละตัว แต่ที่นี่คุณสามารถกำจัดอักขระที่ไม่ใช่ตัวเลขออกจากเซลล์ได้อย่างรวดเร็วดังนี้:

ลบอักขระที่ไม่ใช่ตัวเลขด้วยรหัส VBA

เครื่องมือที่มีประโยชน์ในการลบอักขระที่ไม่ใช่ตัวเลขได้ด้วยคลิกเดียว


ลบอักขระที่ไม่ใช่ตัวเลขด้วยรหัส VBA

หากต้องการลบอักขระที่ไม่ใช่ตัวเลขออกจากช่วงที่มีรหัส VBA โปรดทำดังนี้:

1. คลิก ผู้พัฒนา > ของ Visual Basic เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง. ใน Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่างคลิก สิ่งที่ใส่เข้าไป > โมดูลจากนั้นคัดลอกและวางรหัสต่อไปนี้ลงในโมดูล:

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

2. จากนั้นคลิกปุ่ม ปุ่มเพื่อเรียกใช้รหัสในป๊อปอัพ KutoolsforExcel กล่องโต้ตอบเลือกช่วงที่มีอักขระที่ไม่ใช่ตัวเลขที่คุณต้องการลบจากนั้นคลิกที่ไฟล์ OK ปุ่ม. ดูภาพหน้าจอ:

doc ลบอักขระที่ไม่ใช่ตัวเลข 1 สำเนา

3. จากนั้นอักขระที่ไม่ใช่ตัวเลขทั้งหมดในช่วงที่เลือกจะถูกลบออก

doc ลบอักขระที่ไม่ใช่ตัวเลข 2

หากตัวเลขที่มีจุดทศนิยมคุณสามารถใช้ 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

คุณสามารถดูผลลัพธ์ตามภาพด้านล่างที่แสดง:

doc ลบอักขระที่ไม่ใช่ตัวเลข 3


เครื่องมือที่มีประโยชน์ในการลบอักขระที่ไม่ใช่ตัวเลขได้ด้วยคลิกเดียว

สำหรับการลบอักขระที่ไม่ใช่ตัวเลขในช่วง Kutools สำหรับ Excel's ลบอักขระ ยูทิลิตี้สามารถทำได้ด้วยคลิกเดียว

Kutools สำหรับ Excel : ด้วย Add-in ของ Excel ที่มีประโยชน์มากกว่า 300 รายการทดลองใช้ฟรีโดยไม่มีข้อ จำกัด ใน 30 วัน. 

หลังจากการติดตั้ง Kutools สำหรับ Excelโปรดดำเนินการดังนี้:

1. เน้นช่วงที่คุณต้องการลบอักขระที่ไม่ใช่ตัวเลข คลิก Kutools > ข้อความ > ลบอักขระ.

doc ลบอักขระที่ไม่ใช่ตัวเลข 4

2. ใน ลบอักขระ ให้ทำเครื่องหมายที่ ไม่ใช่ตัวเลข ตัวเลือกใน ลบอักขระ แล้วคลิกไฟล์ OK or ใช้ ปุ่ม. และอักขระที่ไม่ใช่ตัวเลขจะถูกลบออกจากการเลือกทันที ดูภาพหน้าจอ:

doc ลบอักขระที่ไม่ใช่ตัวเลข 5

คลิกเพื่อดาวน์โหลด Kutools สำหรับ Excel และทดลองใช้ฟรีทันที!

สำหรับข้อมูลเพิ่มเติมเกี่ยวกับ ลบอักขระ ของ Kutools for Excel โปรดไปที่ ลบคำอธิบายคุณสมบัติของตัวละคร


การสาธิต: ลบอักขระที่เป็นตัวเลขตัวอักษรไม่สามารถพิมพ์ได้หรือตัวอักษรและตัวเลขคละกันออกจากเซลล์

Kutools สำหรับ Excel: ด้วย Add-in ของ Excel ที่มีประโยชน์มากกว่า 300 รายการให้ทดลองใช้ฟรีโดยไม่มีข้อ จำกัด ใน 30 วัน ดาวน์โหลดและทดลองใช้ฟรีทันที!

บทความที่เกี่ยวข้อง:

สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

🤖 Kutools AI ผู้ช่วย: ปฏิวัติการวิเคราะห์ข้อมูลโดยยึดตาม: การดำเนินการที่ชาญฉลาด   |  สร้างรหัส  |  สร้างสูตรที่กำหนดเอง  |  วิเคราะห์ข้อมูลและสร้างแผนภูมิ  |  เรียกใช้ฟังก์ชัน Kutools...
คุณสมบัติยอดนิยม: ค้นหา เน้น หรือระบุรายการที่ซ้ำกัน   |  ลบแถวว่าง   |  รวมคอลัมน์หรือเซลล์โดยไม่สูญเสียข้อมูล   |   รอบโดยไม่มีสูตร ...
การค้นหาขั้นสูง: VLookup หลายเกณฑ์    VLookup หลายค่า  |   VLookup ข้ามหลายแผ่น   |   การค้นหาที่ไม่ชัดเจน ....
รายการแบบเลื่อนลงขั้นสูง: สร้างรายการแบบหล่นลงอย่างรวดเร็ว   |  รายการแบบหล่นลงขึ้นอยู่กับ   |  เลือกหลายรายการแบบหล่นลง ....
ผู้จัดการคอลัมน์: เพิ่มจำนวนคอลัมน์เฉพาะ  |  ย้ายคอลัมน์  |  สลับสถานะการมองเห็นของคอลัมน์ที่ซ่อนอยู่  |  เปรียบเทียบช่วงและคอลัมน์ ...
คุณสมบัติเด่น: กริดโฟกัส   |  มุมมองการออกแบบ   |   บาร์สูตรใหญ่    สมุดงานและตัวจัดการชีต   |  ห้องสมุดทรัพยากร (ข้อความอัตโนมัติ)   |  เลือกวันที่   |  รวมแผ่นงาน   |  เข้ารหัส/ถอดรหัสเซลล์    ส่งอีเมลตามรายการ   |  ซุปเปอร์ฟิลเตอร์   |   ตัวกรองพิเศษ (กรองตัวหนา/ตัวเอียง/ขีดทับ...) ...
ชุดเครื่องมือ 15 อันดับแรก12 ข้อความ เครื่องมือ (เพิ่มข้อความ, ลบอักขระ, ... )   |   50 + แผนภูมิ ประเภท (แผนภูมิ Gantt, ... )   |   40+ ใช้งานได้จริง สูตร (คำนวณอายุตามวันเกิด, ... )   |   19 การแทรก เครื่องมือ (ใส่ QR Code, แทรกรูปภาพจากเส้นทาง, ... )   |   12 การแปลง เครื่องมือ (ตัวเลขเป็นคำ, การแปลงสกุลเงิน, ... )   |   7 ผสานและแยก เครื่องมือ (แถวรวมขั้นสูง, แยกเซลล์, ... )   |   ... และอื่น ๆ

เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา  คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...

รายละเอียด


แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก

  • เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, Visio และโครงการ
  • เปิดและสร้างเอกสารหลายรายการในแท็บใหม่ของหน้าต่างเดียวกันแทนที่จะเป็นในหน้าต่างใหม่
  • เพิ่มประสิทธิภาพการทำงานของคุณ 50% และลดการคลิกเมาส์หลายร้อยครั้งให้คุณทุกวัน!
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