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

วิธีค้นหาตำแหน่งของหมายเลขแรก / สุดท้ายในสตริงข้อความใน Excel

ตัวอย่างเช่นคุณมีรายการสตริงข้อความซึ่งประกอบด้วยตัวอักษรและตัวเลขผสมกัน ถ้าคุณต้องการหาตำแหน่งของตัวเลขแรกหรือตัวสุดท้ายในแต่ละสตริงคุณจะทำอย่างไร? ที่จริงแล้วการใช้สูตรจะช่วยให้คุณค้นหาตำแหน่งของตัวเลขแรก / สุดท้ายในสตริงข้อความที่ระบุได้อย่างรวดเร็ว ในบทช่วยสอนนี้เราจะแสดงรายละเอียดเกี่ยวกับการจัดการกับปัญหานี้

ค้นหาตำแหน่งของตัวเลขแรกในสตริงข้อความใน Excel
ค้นหาตำแหน่งของตัวเลขสุดท้ายในสตริงข้อความใน Excel


ค้นหาตำแหน่งของตัวเลขแรกในสตริงข้อความใน Excel

ดังภาพหน้าจอด้านล่างสำหรับการค้นหาตำแหน่งของตัวเลขแรกในสตริงข้อความโปรดทำดังนี้

1. เลือกเซลล์ B2 คัดลอกและวางสูตรด้านล่างลงในแถบสูตร:

1). สูตร 1: = MIN (ค้นหา ({0,1,2,3,4,5,6,7,8,9}, A2 & "0123456789"));

2). สูตร 2: =MATCH(TRUE,ABS(CODE(MID(A2,ROW($A$1:INDEX(A:A,LEN(A2))),1))-52.5)<5,0) + Ctrl + เปลี่ยน + เข้าสู่;

3). สูตร 3: =MIN(IF(ISERROR(FIND({1;2;3;4;5;6;7;8;9;0},A2)),"",FIND({1;2;3;4;5;6;7;8;9;0},A2))).

2. จากนั้นตำแหน่งตัวเลขแรกของสตริงแรกจะแสดงในเซลล์ B2 ตอนนี้ลาก Fill Handle ลงไปที่เซลล์ B7 เพื่อเติมช่วงด้านล่าง

จากนั้นตำแหน่งหมายเลขแรกทั้งหมดของสตริงทั้งหมดจะถูกแสดงรายการ


ค้นหาตำแหน่งของตัวเลขสุดท้ายในสตริงข้อความใน Excel

หลังจากค้นหาตำแหน่งของหมายเลขแรกตอนนี้เราเริ่มค้นหาตำแหน่งของตัวเลขสุดท้ายในสตริง

ในส่วนนี้มีสองสูตรสำหรับคุณ

สูตร 1: = MAX (IF (ISNUMBER (ค่า (กลาง (A2, ROW (ทางอ้อม ("1:" & LEN (A2))), 1))), ROW (ทางอ้อม ("1:" & LEN (A2))) ) + Ctrl + เปลี่ยน + เข้าสู่;

สูตร 2: =MAX(IFERROR(FIND({1,2,3,4,5,6,7,8,9,0},A2,ROW(INDIRECT("1:"&LEN(A2)))),0)) + Ctrl + เปลี่ยน + เข้าสู่

1. เลือกเซลล์ B2 คัดลอกและวางสูตรข้างต้นลงในแถบสูตรจากนั้นกด Ctrl + Shift + Enter พร้อมกัน จากนั้นคุณจะเห็นผลลัพธ์ที่แสดงใน B2

2. เลือก B2 ลาก Fill Handle ลงไปที่เซลล์ B7 เพื่อเติมช่วงอัตโนมัติ

จากนั้นคุณจะได้รับตำแหน่งของตัวเลขสุดท้ายทั้งหมดของสตริงข้อความทั้งหมดทันที


แยกข้อความและตัวเลขจากเซลล์เดียวออกเป็นสองคอลัมน์ใน Excel ได้อย่างง่ายดาย:

กับ Kutools สำหรับ Excel's แยกเซลล์ ยูทิลิตี้คุณสามารถแบ่งช่วงของเซลล์ออกเป็นแถวหรือคอลัมน์โดยใช้ตัวคั่นเฉพาะแยกข้อความและตัวเลขหรือแยกข้อความตามความยาวของผู้รับรอง ดาวน์โหลดและทดลองใช้ทันที! (เส้นทางฟรี 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 (15)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Ich habe gerade diese Lösung ausprobiert und es klappt bei mir nicht. Hat sich inzwischen etwas, was die Matrixformel betrifft, geändert?
This comment was minimized by the moderator on the site
Hi Wolfgang,

The formulas provided in this post work well in my case. What result did you get?
This comment was minimized by the moderator on the site
Thought I would let everyone know that I needed to find the last position of the house numbers in an address field in access. The only way I could do this was to export a short query to excel and run this formula. I know there is a way to get the excel functions in access but this was much easier. I had addresses that had varying house number lengths and then you throw in the 1st, 2nd, 3rd...St., Ave into the mix within the street name and you got a major problem parsing a very bad formatted address string.

address examples 1234 nw (or NW) 4th St.
12 West St North (or N)
123,456, and 789 Heritage Circle (or Crc)
123 & 456 N 1st. St

I figured out a way to parse off the first and second example real quick with some research (I would give credit, but right now I can't remember where I got the answer). It involved creating a VBA function to accomplish it. That worked great but I came to a problem when we come to the first "," or "and" or "&".

Using this formula in excel found the last number I needed without choosing the street number. Since most house numbers ended with a space " " between them and the direction segment or the street name segment, I added --- &" " after the find formula. Like this: in an array formula
=MAX(IFERROR(FIND({1,2,3,4,5,6,7,8,9,0}&" ",E2,ROW(INDIRECT("1:"&LEN(E2)))),0))
A quick export back to an access table and wala! you have the number.
202 & 206 N Blanche Ave = 9

Now I know I could probably parse the rest of the address in excel but it actually worked real well in Access, so I just decided to do the rest there.

If there is a way to do it all in Access, I couldn't find it or figure it out.
This comment was minimized by the moderator on the site
goood, thanks
This comment was minimized by the moderator on the site
That's what I needed =MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A2&"0123456789"));

thank you very much!
This comment was minimized by the moderator on the site
You are welcome O(∩_∩)O
This comment was minimized by the moderator on the site
how to get this to work in powerpivot
This comment was minimized by the moderator on the site
Hi,
Sorry can't help with this.
This comment was minimized by the moderator on the site
.... and here I thought that I knew Excel well. Bravo!!!!!
This comment was minimized by the moderator on the site
And here is a formula for finding the position of the last numeric character in a string, but WITHOUT using an array formula: =MAX(SEARCH(CHAR(9),SUBSTITUTE("0123456789"&A1,{0,1,2,3,4,5,6,7,8,9},CHAR(9),LEN(A1)+10-LEN(SUBSTITUTE("0123456789"&A1,{0,1,2,3,4,5,6,7,8,9},"")))))-10 The number 10 appearing in this formula, are due to the length of the constant string "0123456789", that is concatenated in this formula.
This comment was minimized by the moderator on the site
Many Thanks , Great
This comment was minimized by the moderator on the site
Hi George, your formula is may meet my requirement. I need similar formula to find out digit position in the string listed in "A" row in B row Required output 8 5 1 4 3 1 3 2 5 5 6 6 1 7 9 9 1 1 6 0 9 3 0 2 7 4 9 3 6 5 5 7 4 9 8 10 2 10 0 8 1 9
This comment was minimized by the moderator on the site
This was exactly what I wanted. Thank you.
This comment was minimized by the moderator on the site
The function 1). Formula 1: =MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A2&"0123456789")); It's absolutely what i needed and extremely cool! Thanks so much! Jon
This comment was minimized by the moderator on the site
Hats off mate..
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations