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

วิธีลบอักขระพิเศษออกจากสตริงใน Excel

ผู้เขียน: Xiaoyang แก้ไขล่าสุด: 2020-04-21

หากมีอักขระพิเศษบางตัวเช่น % ^ & * () ภายในสตริงข้อความและตอนนี้คุณต้องการลบอักขระเฉพาะเหล่านี้ออกจากสตริงเซลล์ ในการลบทีละรายการจะใช้เวลานานที่นี่ฉันจะแนะนำเคล็ดลับง่ายๆสำหรับการแก้ปัญหานี้ใน Excel

ลบอักขระพิเศษบางตัวออกจากสตริงข้อความด้วย User Defined Function

ลบอักขระพิเศษออกจากสตริงข้อความด้วย Kutools for Excel


ลูกศรสีฟ้าฟองขวา ลบอักขระพิเศษบางตัวออกจากสตริงข้อความด้วย User Defined Function

รหัส VBA ต่อไปนี้สามารถช่วยคุณลบอักขระเฉพาะที่คุณต้องการได้โปรดดำเนินการดังนี้:

1. ค้างไว้ ALT + F11 คีย์เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

2. คลิก สิ่งที่ใส่เข้าไป > โมดูลและวางรหัสต่อไปนี้ในไฟล์ โมดูล หน้าต่าง.

รหัส VBA: ลบอักขระพิเศษบางตัวออกจากสตริงข้อความ

Function RemoveSpecial(Str As String) As String
'updatebyExtendoffice 20160303
    Dim xChars As String
    Dim I As Long
    xChars = "#$%()^*&"
    For I = 1 To Len(xChars)
        Str = Replace$(Str, Mid$(xChars, I, 1), "")
    Next
    RemoveSpecial = Str
End Function

3. จากนั้นบันทึกและปิดรหัสนี้กลับไปที่แผ่นงานและป้อนสูตรนี้: = removespecial (A2) ลงในเซลล์ว่างที่คุณต้องการใส่ผลลัพธ์ดูภาพหน้าจอ:

doc ลบอักขระพิเศษ 1

4. จากนั้นลากที่จับเติมลงไปที่เซลล์ที่คุณต้องการใช้สูตรนี้และอักขระพิเศษทั้งหมดที่คุณไม่ต้องการถูกลบออกจากสตริงข้อความดูภาพหน้าจอ:

doc ลบอักขระพิเศษ 2

หมายเหตุ: ในโค้ดด้านบนคุณสามารถเปลี่ยนตัวอักษรพิเศษได้ # $% () ^ * & ให้กับคนอื่น ๆ ที่คุณต้องการลบ


emove ตัวเลขอัลฟาหรืออักขระพิเศษอื่น ๆ จากสตริงข้อความ

Kutools สำหรับ Excel's ลบอักขระ คุณสมบัติสามารถช่วยให้คุณลบทั้งหมดได้อย่างรวดเร็ว เป็นตัวเลข, แอลฟา, ไม่ใช่ตัวเลข, ไม่ใช่อัลฟ่า, ไม่พิมพ์, อักขระเฉพาะอื่น ๆ จากสตริงข้อความตามที่คุณต้องการ คลิกเพื่อดาวน์โหลดและทดลองใช้ Kutools for Excel ฟรีทันที!

doc ลบอักขระพิเศษ 7

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


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

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

1. เลือกสตริงข้อความที่คุณต้องการลบอักขระพิเศษบางตัว

2. คลิก Kutools > ข้อความ > ลบอักขระดูภาพหน้าจอ:

3. ใน ลบอักขระ กล่องโต้ตอบตรวจสอบ ประเพณี ภายใต้ ลบอักขระ และป้อนอักขระพิเศษที่คุณต้องการลบดูภาพหน้าจอ:

doc ลบอักขระพิเศษ 4

4. จากนั้นคลิก Ok or ใช้ ปุ่มอักขระที่คุณระบุในไฟล์ ประเพณี กล่องข้อความถูกลบออกจากสตริงข้อความพร้อมกันดูภาพหน้าจอ:

doc ลบอักขระพิเศษ 5 2 doc ลบอักขระพิเศษ 6

คลิกเพื่อดาวน์โหลดและทดลองใช้ 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 (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Excelllent .. Five Stars.. thanks a lot
This comment was minimized by the moderator on the site
Thanks for this code
Function RemoveSpecial(Str As String) As String
'updatebyExtendoffice 20160303
Dim xChars As String
Dim I As Long
xChars = "#$%()^*&"
For I = 1 To Len(xChars)
Str = Replace$(Str, Mid$(xChars, I, 1), "")
Next
RemoveSpecial = Str
End Function

But it is possible that that can remove specific text? like "ab", "abc", "bc" and etc.
This comment was minimized by the moderator on the site
With Emoji need remove, how ?
This comment was minimized by the moderator on the site
Rather than searching for specific special characters, how about if you want to search for and replace ALL special characters. In other words, how would you write the search for NOT one of the following characters: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
This comment was minimized by the moderator on the site
Hi, Nick,
Do you want to remove all ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 characters from the cells?
Looking forward to your reply, thank you!
This comment was minimized by the moderator on the site
No. I want to keep only "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
This comment was minimized by the moderator on the site
Nick,
Maybe the below VBA code can solve your problem, please try:

Sub RemoveNotAlphasNotNum()
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 "[a-z.]" Or xTemp Like "[A-Z.]" Or xTemp Like "[0-9.]" Then
xStr = xTemp
Else
xStr = ""
End If
xOut = xOut & xStr
Next i
Rng.Value = xOut
Next
End Sub


Hope it can help you!
This comment was minimized by the moderator on the site
Hmm I wonder, does it only work in the worksheet you've originally pasted the code in?
As for that one it only seems to work, not for any new workbook you open
This comment was minimized by the moderator on the site
Hello, Kim,
The VBA code can only applied in one workbook, if you want to apply it in a new workbook, you should copy and paste the code into your new workbook again.
Thank you!
This comment was minimized by the moderator on the site
Hi guys,

I've applied the =removespecial(A2) code and it works perfectly in one worksheet but then in the other it gives me an invalid #NAME? error.
I checked the "format cells" and it's both on general and I've copied the same text + formula to both worksheets but it won't work.
Any clue what this might cause this?

Thanks and thank you so much for this code.
Saves me hours and hours of work!

Regards, Kim
This comment was minimized by the moderator on the site
Function GetWordWOSpecChar(Rng As Range)
'paste in VBA module, Use as a Formula
'Created by Deepak Sharma
Arr = Array("48", "49", "50", "51", "52", "53", "54", "55", _
"56", "57", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", _
"76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", _
"89", "90", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", _
"107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", _
"118", "119", "120", "121", "122")

For i = 1 To Len(Rng.Value)
txt = Mid(Rng.Value, i, 1)
For g = 1 To UBound(Arr)
If txt = Chr(Arr(g)) Then GetWord = Right(Rng.Value, Len(Rng.Value) - (i - 1)): Exit Function
Next g
Next i

End Function
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations