extracting specific numbers from a range

drjpb

Board Regular
Joined
Dec 11, 2013
Messages
61
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I want to extract document numbers from a range on regular basis. The document no. consists of 8 digits and starts with17??????,11??????, 12??????, 13??????, 15?????? and 61??????. In future this criteria may increase (e.g., 18.... & 62.... etc.).
If the criteria repeats, i want the document number only once.
If 17* & 61* both appear in a cell, i want priority for 17*, priority same as defined above (17,11,12,13,15 or 61)
Also if the criteria is not meet i want 0 in that cell (If any of the above criteria not met).
Final result should be all numbers (to remove all text characters).

If i am not asking too much, can we use criteria from a separate sheet in same workbook, let's say i have a sheet named as criteria and Cell A1 contains "17", A2 contains "11", and so on, priority as ascending, so that if in future novice users want to add more to the criteria or rearrange priority, it will be easy for them to rearrange or add by just typing in Cell A7, A8...

Thanking in advance.


Note:
In one cell, data showing following: "17053012--288017000731", i want 17053012 and not 17000731 (which is part of another number).
In one cell, data is "61916456--288017000731يوسف حسين عبيد العتيبي-17054101 KFC-القطاع التجاري", so 17054101 is required, as per the priority.
Again in one cell, data is "مقدم استمارة 17034091 فاتورة 61907541 KFC-القطاع التجاري-دفعات", here again 17034091 is expected.


Find below sample data, which contain mix numbers, as well as text (mostly unicode).

Sample:
PEF Salesdoc No. 17052671 Ref. CPS
PEF Salesdoc No. 17053268 Ref. CPS
PEF Salesdoc No. 17054276 Ref. CPS
PEF Salesdoc No. 17053759 Ref. CPS
17052983--0 KFC-القطاع التجاري-دفعات مقدمة
17053903--خلف KFC-القطاع التجاري-دفعات مقدمة
17054059--بدر KFC-القطاع التجاري-دفعات مقدمة
17052754--مقدم KFC-القطاع التجاري-دفعات مقدمة
17053745--مقدم KFC-القطاع التجاري-دفعات مقدمة
17052143--1705243 KFC-القطاع التجاري-دفعات مقدمة
1703536--17053536 KFC-القطاع التجاري-دفعات مقدمة
17053861--17053861 KFC-القطاع التجاري-دفعات مقدمة
17054028--17054028 KFC-القطاع التجاري-دفعات مقدمة
17052794--17052794 KFC-القطاع التجاري-دفعات مقدمة
17052903--17052903 KFC-القطاع التجاري-دفعات مقدمة
17053566--17053566 KFC-القطاع التجاري-دفعات مقدمة
17053838--17053838 KFC-القطاع التجاري-دفعات مقدمة
17053865--17053865 KFC-القطاع التجاري-دفعات مقدمة
17053890--17053890 KFC-القطاع التجاري-دفعات مقدمة
17053899--17053899 KFC-القطاع التجاري-دفعات مقدمة
17054011--17054011 KFC-القطاع التجاري-دفعات مقدمة
17053994 KFC-القطاع التجاري-دفعات مقدمة
17052320--17052320 KFC-القطاع التجاري-دفعات مقدمة
17053778--17053778 KFC-القطاع التجاري-دفعات مقدمة
17053766--17053766 KFC-القطاع التجاري-دفعات مقدمة
17053991--17053991 KFC-القطاع التجاري-دفعات مقدمة
17054120--17054120 KFC-القطاع التجاري-دفعات مقدمة
17053997--17053997 KFC-القطاع التجاري-دفعات مقدمة
17051249--17051249 KFC-القطاع التجاري-دفعات مقدمة
17053900--17053900 KFC-القطاع التجاري-دفعات مقدمة
17054049--17054049 KFC-القطاع التجاري-دفعات مقدمة
17053564--17053564 KFC-القطاع التجاري-دفعات مقدمة
17054108--17054108 KFC-القطاع التجاري-دفعات مقدمة
17053798--17053798 KFC-القطاع التجاري-دفعات مقدمة
17045562 KFC-القطاع التجاري-دفعات مقدمة
17048097 KFC-القطاع التجاري-دفعات مقدمة
17053859 KFC-القطاع التجاري-دفعات مقدمة
17054005 KFC-القطاع التجاري-دفعات مقدمة
17053993--17053993 KFC-القطاع التجاري-دفعات مقدمة
17053888--17053888 KFC-القطاع التجاري-دفعات مقدمة
17054126--17054126 KFC-القطاع التجاري-دفعات مقدمة
17054146--17054146 KFC-القطاع التجاري-دفعات مقدمة
17050154--17050154 KFC-القطاع التجاري-دفعات مقدمة
17053296--55887272 KFC-القطاع التجاري-دفعات مقدمة
17054047--55576565 KFC-القطاع التجاري-دفعات مقدمة
17054201--51222453 KFC-القطاع التجاري-دفعات مقدمة
17054261--55515315 KFC-القطاع التجاري-دفعات مقدمة
17053788 KFC-القطاع التجاري-دفعات مقدمة
17053455--275022600018 KFC-القطاع التجاري-دفعات مقدمة
17050961--283082700707 KFC-القطاع التجاري-دفعات مقدمة
17051621--273030500384 KFC-القطاع التجاري-دفعات مقدمة
17053553--274050700599 KFC-القطاع التجاري-دفعات مقدمة
17052519--290080901105 KFC-القطاع التجاري-دفعات مقدمة
17052947--252110801088 KFC-القطاع التجاري-دفعات مقدمة
17054188--268011600316 KFC-القطاع التجاري-دفعات مقدمة
17053012--288017000731 KFC-القطاع التجاري-دفعات مقدمة
17053229--285070500985 KFC-القطاع التجاري-دفعات مقدمة
17053264--280033101528 KFC-القطاع التجاري-دفعات مقدمة
17053141--268012300323 KFC-القطاع التجاري-دفعات مقدمة
17052692--271030100437 KFC-القطاع التجاري-دفعات مقدمة
17053379--279122300272 KFC-القطاع التجاري-دفعات مقدمة
17053556--293120401222 KFC-القطاع التجاري-دفعات مقدمة
17054138--282112401181 KFC-القطاع التجاري-دفعات مقدمة
17053305--265041507768 KFC-القطاع التجاري-دفعات مقدمة
17053079--285072302253 KFC-القطاع التجاري-دفعات مقدمة
17053085--288030901569 KFC-القطاع التجاري-دفعات مقدمة
17053828--عبدالعزيز سعود KFC-القطاع التجاري-دفعات مقدمة
17053690--286071401713ب.م KFC-القطاع التجاري-دفعات مقدمة
17054176--284102500716ب.م KFC-القطاع التجاري-دفعات مقدمة
17052642--استماره 17052642 KFC-القطاع التجاري-دفعات مقدمة
استماره 17054158 KFC-القطاع التجاري-دفعات مقدمة
17054106--استماره 17054106 KFC-القطاع التجاري-دفعات مقدمة
17054178--استماره 17054178 KFC-القطاع التجاري-دفعات مقدمة
غازي 288100501633 KFC-القطاع التجاري-دفعات مقدمة
17054008--262060302801-self KFC-القطاع التجاري-دفعات مقدمة
17053540--فاتوره رقم17053450 KFC-القطاع التجاري-دفعات مقدمة
17053216--FATMA-260070600504 KFC-القطاع التجاري-دفعات مقدمة
فاتوره رقم61916503 KFC-القطاع التجاري-دفعات مقدمة
الاستماره 17053590 KFC-القطاع التجاري-دفعات مقدمة
استماره رقم17052304 KFC-القطاع التجاري-دفعات مقدمة
استمارة رقم17052694 KFC-القطاع التجاري-دفعات مقدمة
استمارة رقم17053259 KFC-القطاع التجاري-دفعات مقدمة
17053435--استماره رقم 17053435 KFC-القطاع التجاري-دفعات مقدمة
17054000--استماره رقم 17054000 KFC-القطاع التجاري-دفعات مقدمة
17054202--استماره رقم 17054202 KFC-القطاع التجاري-دفعات مقدمة
17054216--استماره رقم 17054216 KFC-القطاع التجاري-دفعات مقدمة
استمارة رقم 17054099 KFC-القطاع التجاري-دفعات مقدمة
استمارة رقم 17053996 KFC-القطاع التجاري-دفعات مقدمة
استمارة رقم 17053541 KFC-القطاع التجاري-دفعات مقدمة
استمارة رقم 17052137 KFC-القطاع التجاري-دفعات مقدمة
17053579--مقدم مرابحة 17053579 KFC-القطاع التجاري-دفعات مقدمة
17054137--استماره رقم 17054137 KFC-القطاع التجاري-دفعات مقدمة
مقدم مرابحه 17051279 KFC-القطاع التجاري-دفعات مقدمة
17053660--مقدم تجاريه 17053660 KFC-القطاع التجاري-دفعات مقدمة
17053863--291090301749-17053863 KFC-القطاع التجاري-دفعات مقدمة
17054154--17054154-259060301721 KFC-القطاع التجاري-دفعات مقدمة
17053591--مقدم استماره 17053491 KFC-القطاع التجاري-دفعات مقدمة
17053547--مقدم استماره 17053547 KFC-القطاع التجاري-دفعات مقدمة
17054165--مقدم استماره 17054165 KFC-القطاع التجاري-دفعات مقدمة
17054179--مقدم استماره 17054179 KFC-القطاع التجاري-دفعات مقدمة
17054211--مقدم استمارة 17054211 KFC-القطاع التجاري-دفعات مقدمة
17054181--مقدم استماره 17054181 KFC-القطاع التجاري-دفعات مقدمة
17053982--مقدم استماره/17053982 KFC-القطاع التجاري-دفعات مقدمة
17053655--رقم الاستماره 17053655 KFC-القطاع التجاري-دفعات مقدمة
رقم الاستماره 17034951 KFC-القطاع التجاري-دفعات مقدمة
رقم الاستماره 17053543 KFC-القطاع التجاري-دفعات مقدمة
استماره رقم - 17053767 KFC-القطاع التجاري-دفعات مقدمة
17053870--مقدم مرابحة / 17053870 KFC-القطاع التجاري-دفعات مقدمة
17053867--رقم الاستمارة 17053867 KFC-القطاع التجاري-دفعات مقدمة
17051997--مقدم استماره رقم17051997 KFC-القطاع التجاري-دفعات مقدمة
17053852--مقدم استماره رقم 17053852 KFC-القطاع التجاري-دفعات مقدمة
17054013--مقدم استماره رقم:17054013 KFC-القطاع التجاري-دفعات مقدمة
مقدم استمارة رقم 17053843 KFC-القطاع التجاري-دفعات مقدمة
17051414--مقدم استماره رقم :17051414 KFC-القطاع التجاري-دفعات مقدمة
17054034--مقدم استماره رقم :17054034 KFC-القطاع التجاري-دفعات مقدمة
17053981--مقدم استماره رقم / 17053981 KFC-القطاع التجاري-دفعات مقدمة
17053377--دفع مقدم مرابحه - يعقوب الشطي KFC-القطاع التجاري-دفعات مقدمة
17053083--id 283081300111 athari eleissa KFC-القطاع التجاري-دفعات مقدمة
17053711--عبدالله مطلق شباب 279120401133 KFC-القطاع التجاري-دفعات مقدمة
17050642--رقم الاستماره 17050642 محمد نصر KFC-القطاع التجاري-دفعات مقدمة
17054029--مقدم تجاريه استماره رقم 17054029 KFC-القطاع التجاري-دفعات مقدم
17053658--مقدم مرابحه استماره رقم 17053658 KFC-القطاع التجاري-دفعات مقدم
17054037--استماره17054037عائشه جديع العجمي280052301103 KFC-القطاع التجار
احمد انور بوناشي 17054033 مجمع الوزارات KFC-القطاع التجاري-دفع
17053555--مقدم استمارة 17053555 ب/م 280021800989 KFC-القطاع التجاري-دفعا
17053704--285032100358-مقدم تورق رقم الاستماره 17053704 KFC-القطاع التجا
17053808--272031500488-مقدم تورق رقم الاستماره 17053808 KFC-القطاع التجا
17054036--288050101059-مقدم تورق رقم الاستماره 17054036 KFC-القطاع التجا
17054117--284031100394-مقدم تورق رقم الاستماره 17054117 KFC-القطاع التجا
61916456--288017000731يوسف حسين عبيد العتيبي-17054101 KFC-القطاع التجاري
17054041--جلين جوي يدانيس توان - 270061303478 - 17054041 KFC-القطاع التج
مقدم استمارة 17034091 فاتورة 61907541 KFC-القطاع التجاري-دفعات

<tbody>
</tbody>


This is the final Result i am expecting for the above sample:

FINAL RESULT:

12447712
17050256
17053531
17053616
17053712
17053884
17054249
13191360
17049914
17051251
17052716
17053669
17053979
17054048
17054250
17054263
12447693
17052702
17053554
17053697
17053720
17053720
17053839
17053921
17053933
17054007
17054064
17054265
17052153
17052296
17052784
17053032
17053408
17053589
17053825
17053926
17053985
17053737
17054075
12447758
17053001
17054164
17053734
17053530
17047607
12447702
17053533
17053856
17053967
17054225
17054239
17049683
17053999
17054061
17053946
17054092
17052788
17052932
17053622
17054174
12447584
17053895
12447704
17054025
17053949
17050680
17054258
17047216
17052882
17053108
17054035
17054155
17054242
17054248
17053479
17054267
11956310
17053748
17053918
17054094
17054156
17054236
17053772
17051865
17053181
17054073
17053724
17053983
17054039
17054168
17053563
17053356
17054214
17052426
17053686
17053872
17054229
17052417
17052671
17053268
17054276
17053759
17052983
17053903
17054059
17052754
17053745
17052143
17053536
17053861
17054028
17052794
17052903
17053566
17053838
17053865
17053890
17053899
17054011
17053994
17052320
17053778
17053766
17053991
17054120
17053997
17051249
17053900
17054049
17053564
17054108
17053798
17045562
17048097
17053859
17054005
17053993
17053888
17054126
17054146
17050154
17053296
17054047
17054201
17054261
17053788
17053455
17050961
17051621
17053553
17052519
17052947
17054188
17053012
17053229
17053264
17053141
17052692
17053379
17053556
17054138
17053305
17053079
17053085
17053828
17053690
17054176
17052642
17054158
17054106
17054178
0
17054008
17053540
17053216
61916503
17053590
17052304
17052694
17053259
17053435
17054000
17054202
17054216
17054099
17053996
17053541
17052137
17053579
17054137
17051279
17053660
17053863
17054154
17053591
17053547
17054165
17054179
17054211
17054181
17053982
17053655
17034951
17053543
17053767
17053870
17053867
17051997
17053852
17054013
17053843
17051414
17054034
17053981
17053377
17053083
17053711
17050642
17054029
17053658
17054037
17054033
17053555
17053704
17053808
17054036
17054117
17034091
17054041
17034091
17053201
17042626
17050347
17054023
17047811

<tbody>
</tbody>

Once again Thanking you.
 
1. I'm not sure that I can get my head around the right to left v left to right issue.

2. Your last post included some html that made the whole thread disappear. I have fixed that but the moderators have been investigating a number of threads like that. Can you give us any information about where/how you prepared your post #10? In particular, that last part with border around the data sample.
 
Last edited:
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
1. I'm not sure that I can get my head around the right to left v left to right issue.
I am at a loss on this issue as well.


2. You last post included some html that made the whole thread disappear. I have fixed that...
Phew! I thought I had done something wrong when I could not get back into the thread no matter what I did. Thanks for fixing it.


In particular, that last part with border around the data sample.
If you are referring to the bordered item in Message #10..
It is just text in a table with a different kind of border
 
Last edited:
Upvote 0
If you are referring to the bordered item in Message #10..
It is just text in a table with a different kind of border
But it wasn't before I fixed it, there was some extra html and we are trying to determine the source(s)/cause(s) of such html as it is corrupting a significant number of threads in recent weeks.
 
Upvote 0
But it wasn't before I fixed it, there was some extra html and we are trying to determine the source(s)/cause(s) of such html as it is corrupting a significant number of threads in recent weeks.


i can't remember, it was copied from MS Word or MS Excel (2013), just simple copy & paste into the thread.
 
Upvote 0
1. I'm not sure that I can get my head around the right to left v left to right issue.


I was referring to the language, we use Arabic in Kuwait & it's written right to left, which sometimes causes complications specially with the combination of text & numbers.
For example in a cell data will appear text & number, where as if we switch it other way, it may appear number & text.
To avoid these kind of confusions, we usually use Windows shortcuts (Right Shift + Ctrl or Left Shift + Ctrl), in order to view the data in it's correct form.

Sorry for any inconvenient.

Thanks a lot, the provided code is best solution for my problem, it will save our time & daily efforts.
Thanking you once again.
 
Upvote 0
i can't remember, it was copied from MS Word or MS Excel (2013), just simple copy & paste into the thread.

I forget to mention browser, it's Chrome [FONT=&quot]Version 52.0.2743.116 m (64-bit)
[/FONT]
I used quick reply while replying to the message, and once i pressed the "Post Quick Reply", page became blank (white). I tried reloading it but nothing happened.
BTW this version was released on 3rd August, it may be from the browser (Chrome Releases: Stable Channel Update for Desktop).[FONT=&quot]
[/FONT]
I am using it on Win 10 enterprise, 64bit.

Hope this will helps
 
Upvote 0
Thanks for the extra information about your posting. I have passed it on. If it happens again, please try to note anything else that might help us track down the cause.
 
Upvote 0
<table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:329px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >B</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td >PEF Salesdoc No. 17053759 Ref. CPS</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td >17052983--0 KFC-القطاع التجاري-دفعات مقدمة</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td >17053903--خلف KFC-القطاع التجاري-دفعات مقدمة</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td >17054059--بدر KFC-القطاع التجاري-دفعات مقدمة</td></tr></table>
 
Last edited:
Upvote 0
I would like to add for novice users, that the code provided (by Peter_SSs), in order for it to work properly, you need to have data in "Sheet1", and criteria in "Sheet2". If same name sheets not found in the workbook, code will not work.

Sheet1 (Sample):
<table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:458px;" /><col style="width:92px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td><td >B</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td >PEF Salesdoc No. 17052671 Ref. CPS</td><td style="background-color:#92d050; text-align:right; ">17052671</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td >PEF Salesdoc No. 17053268 Ref. CPS</td><td style="background-color:#92d050; text-align:right; ">17053268</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td >PEF Salesdoc No. 17054276 Ref. CPS</td><td style="background-color:#92d050; text-align:right; ">17054276</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td >PEF Salesdoc No. 17053759 Ref. CPS</td><td style="background-color:#92d050; text-align:right; ">17053759</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td >17052983--0 KFC-القطاع التجاري-دفعات مقدمة</td><td style="background-color:#92d050; text-align:right; ">17052983</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td >17053903--خلف KFC-القطاع التجاري-دفعات مقدمة</td><td style="background-color:#92d050; text-align:right; ">17053903</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td >17054059--بدر KFC-القطاع التجاري-دفعات مقدمة</td><td style="background-color:#92d050; text-align:right; ">17054059</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >8</td><td >17052754--مقدم KFC-القطاع التجاري-دفعات مقدمة</td><td style="background-color:#92d050; text-align:right; ">17052754</td></tr></table>


Sheet2 (Criteria):-

<table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:64px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td style="text-align:right; ">17</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td style="text-align:right; ">14</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td style="text-align:right; ">13</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td style="text-align:right; ">12</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td style="text-align:right; ">11</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td style="text-align:right; ">61</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td style="text-align:right; ">62</td></tr></table>
 
Upvote 0
I would like to add for novice users, that the code provided (by Peter_SSs), in order for it to work properly, you need to have data in "Sheet1", and criteria in "Sheet2". If same name sheets not found in the workbook, code will not work.
1. The code was provided by Rick Rothstein, not by me. :)

2. The sheets do not have to be named that way, they can be named as whatever you want, and alter the code to match your names:

Code:
Sub DocumentNumbers()
  .
  .

  Set WSdata = Sheets("[COLOR="#FF0000"][B]Sheet1[/B][/COLOR]")
  Set WScriteria = Sheets("[COLOR="#FF0000"][B]Sheet2[/B][/COLOR]")
 .
 .
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top