Extract only 3 first sign "1", "X" Or "2" appear in the row

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000

Hi,

Data In columns C:P, R:AE are the result columns.

I want VBA or Formula which can extract only 3 first sign "1", "X" Or "2" find in the each row

For example... there are 14 positions of 3 signs "1X2" in columns C:P
Search for 1st sign in the row 6 there is "1" in the C6 position P1, Extract Place "1" in the R6 Position P1.
Search for 2nd sign "X" is in the D6 Position P2, Extract Place "X" in the S6 Position P2.
Finally search for 3rd sign "2" is in the E6 Position P3, Extract Place "X" in the T6 Position P3.

Continue so on.... for all next rows

Note: colours are filled just to explain the example clearer.

Example data.


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAF
1
2
3
4
5P1P2P3P4P5P6P7P8P9P10P11P12P13P14EMP1P2P3P4P5P6P7P8P9P10P11P12P13P14
61X2221XX22XX111X2
71X11XX22XX11XX1X2
81X1221X11X12211X2
9X1X1X11X111XX1X1
10XXX1111X1X212XX12
112X1112XXX111212X1
12X1XX1111111X11X1
131XX12121112X2X1X2
14X2X11X1111X11XX21
15111111XXX1112X1X2
161212X112X2111X12X
171XX112XX1X11X11X2
181XX11211221X111X2
19111X1111X111111X
20X12X1112X112XXX12
21111X1XX1X111111X
2211111XX21111121X2
2311111111112XX112X
2412211111111X1112X
2511X111111111211X2
26XXX111X112X111X12
27X211211111XX1XX21
281X221112XX111X1X2
2921XX11XX1X111121X
301X12211112111X1X2
3111X122211X1X1X1X2
3221X1X1X111111121X
33X11111212XX1XXX12
341211211122212212
35X1111X1211X1XXX12
362X111XX11X11X12X1
371X2X1X1111121X1X2
38X1XX1X11X12211X12
391XX12X11X1X1211X2
401X11X1XX21111X1X2
41121111X1XX1X2212X
42X111111121221XX12
432XX11X11XXXX1X2X1
44X211X112111121X21
451XX1111111X11X1X
46XX111XX21111XXX12
47111X1X1111X1111X
48XX11X111111111X1
49111X1111211X111X2
5011111XX1X2XXXX1X2
51111121XXX1111112X
522X11X11XX111122X1
531XX111111212121X2
541111X11XXX11X11X
55X111X121112X11X12
5611XX1X11XXX2111X2
57122111X21XXX1X12X
5811X1121111X1X11X2
5912211X11111X1X12X
60111121X1221X1X12X
61211X111X11XX2X21X
621111X11X1121121X2
631111112121112X12X
641111111111111X1X
65122111111XX11X12X
66
67
Sheet1


Thank you in advance

Regards,
Kishan
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
AA
AB
AC
AD
AE
1
2
3
4
5
P1P2P3P4P5P6P7P8P9P10P11P12P13P14EMP1P2P3P4P5P6P7P8P9P10P11P12P13P14
6
1​
X
2​
2​
2​
1​
XX
2​
2​
XX
1​
1​
1​
X
2​
7
1​
X
1​
1​
XX
2​
2​
XX
1​
1​
XX
1​
X
2​
8
1​
X
1​
2​
2​
1​
X
1​
1​
X
1​
2​
2​
1​
1​
X
2​
9
X
1​
X
1​
X
1​
1​
X
1​
1​
1​
XX
1​
X
1​
10
XXX
1​
1​
1​
1​
X
1​
X
2​
1​
2​
XX
1​
2​
11
2​
X
1​
1​
1​
2​
XXX
1​
1​
1​
2​
1​
2​
X
1​
12
X
1​
XX
1​
1​
1​
1​
1​
1​
1​
X
1​
1​
X
1​
13
1​
XX
1​
2​
1​
2​
1​
1​
1​
2​
X
2​
X
1​
X
2​
14
X
2​
X
1​
1​
X
1​
1​
1​
1​
X
1​
1​
XX
2​
1​
15
1​
1​
1​
1​
1​
1​
XXX
1​
1​
1​
2​
X
1​
X
2​
16
1​
2​
1​
2​
X
1​
1​
2​
X
2​
1​
1​
1​
X
1​
2​
X
17
1​
XX
1​
1​
2​
XX
1​
X
1​
1​
X
1​
1​
X
2​
18
1​
XX
1​
1​
2​
1​
1​
2​
2​
1​
X
1​
1​
1​
X
2​
19
1​
1​
1​
X
1​
1​
1​
1​
X
1​
1​
1​
1​
1​
1​
X
20
X
1​
2​
X
1​
1​
1​
2​
X
1​
1​
2​
XXX
1​
2​
21
1​
1​
1​
X
1​
XX
1​
X
1​
1​
1​
1​
1​
1​
X
22
1​
1​
1​
1​
1​
XX
2​
1​
1​
1​
1​
1​
2​
1​
X
2​
23
1​
1​
1​
1​
1​
1​
1​
1​
1​
1​
2​
XX
1​
1​
2​
X
24
1​
2​
2​
1​
1​
1​
1​
1​
1​
1​
1​
X
1​
1​
1​
2​
X
25
1​
1​
X
1​
1​
1​
1​
1​
1​
1​
1​
1​
2​
1​
1​
X
2​
26
XXX
1​
1​
1​
X
1​
1​
2​
X
1​
1​
1​
X
1​
2​
27
X
2​
1​
1​
2​
1​
1​
1​
1​
1​
XX
1​
XX
2​
1​
28
1​
X
2​
2​
1​
1​
1​
2​
XX
1​
1​
1​
X
1​
X
2​
29
2​
1​
XX
1​
1​
XX
1​
X
1​
1​
1​
1​
2​
1​
X
30
1​
X
1​
2​
2​
1​
1​
1​
1​
2​
1​
1​
1​
X
1​
X
2​
31
1​
1​
X
1​
2​
2​
2​
1​
1​
X
1​
X
1​
X
1​
X
2​
32
2​
1​
X
1​
X
1​
X
1​
1​
1​
1​
1​
1​
1​
2​
1​
X
33
X
1​
1​
1​
1​
1​
2​
1​
2​
XX
1​
XXX
1​
2​
34
1​
2​
1​
1​
2​
1​
1​
1​
2​
2​
2​
1​
2​
2​
1​
2​
35
X
1​
1​
1​
1​
X
1​
2​
1​
1​
X
1​
XXX
1​
2​
36
2​
X
1​
1​
1​
XX
1​
1​
X
1​
1​
X
1​
2​
X
1​
37
1​
X
2​
X
1​
X
1​
1​
1​
1​
1​
2​
1​
X
1​
X
2​
38
X
1​
XX
1​
X
1​
1​
X
1​
2​
2​
1​
1​
X
1​
2​
39
1​
XX
1​
2​
X
1​
1​
X
1​
X
1​
2​
1​
1​
X
2​
40
1​
X
1​
1​
X
1​
XX
2​
1​
1​
1​
1​
X
1​
X
2​
41
1​
2​
1​
1​
1​
1​
X
1​
XX
1​
X
2​
2​
1​
2​
X
42
X
1​
1​
1​
1​
1​
1​
1​
2​
1​
2​
2​
1​
XX
1​
2​
43
2​
XX
1​
1​
X
1​
1​
XXXX
1​
X
2​
X
1​
44
X
2​
1​
1​
X
1​
1​
2​
1​
1​
1​
1​
2​
1​
X
2​
1​
45
1​
XX
1​
1​
1​
1​
1​
1​
1​
X
1​
1​
X
1​
X
46
XX
1​
1​
1​
XX
2​
1​
1​
1​
1​
XXX
1​
2​
47
1​
1​
1​
X
1​
X
1​
1​
1​
1​
X
1​
1​
1​
1​
X
48
XX
1​
1​
X
1​
1​
1​
1​
1​
1​
1​
1​
1​
X
1​
49
1​
1​
1​
X
1​
1​
1​
1​
2​
1​
1​
X
1​
1​
1​
X
2​
50
1​
1​
1​
1​
1​
XX
1​
X
2​
XXXX
1​
X
2​
51
1​
1​
1​
1​
2​
1​
XXX
1​
1​
1​
1​
1​
1​
2​
X
52
2​
X
1​
1​
X
1​
1​
XX
1​
1​
1​
1​
2​
2​
X
1​
53
1​
XX
1​
1​
1​
1​
1​
1​
2​
1​
2​
1​
2​
1​
X
2​
54
1​
1​
1​
1​
X
1​
1​
XXX
1​
1​
X
1​
1​
X
55
X
1​
1​
1​
X
1​
2​
1​
1​
1​
2​
X
1​
1​
X
1​
2​
56
1​
1​
XX
1​
X
1​
1​
XXX
2​
1​
1​
1​
X
2​
57
1​
2​
2​
1​
1​
1​
X
2​
1​
XXX
1​
X
1​
2​
X
58
1​
1​
X
1​
1​
2​
1​
1​
1​
1​
X
1​
X
1​
1​
X
2​
59
1​
2​
2​
1​
1​
X
1​
1​
1​
1​
1​
X
1​
X
1​
2​
X
60
1​
1​
1​
1​
2​
1​
X
1​
2​
2​
1​
X
1​
X
1​
2​
X
61
2​
1​
1​
X
1​
1​
1​
X
1​
1​
XX
2​
X
2​
1​
X
62
1​
1​
1​
1​
X
1​
1​
X
1​
1​
2​
1​
1​
2​
1​
X
2​
63
1​
1​
1​
1​
1​
1​
2​
1​
2​
1​
1​
1​
2​
X
1​
2​
X
64
1​
1​
1​
1​
1​
1​
1​
1​
1​
1​
1​
1​
1​
X
1​
X
65
1​
2​
2​
1​
1​
1​
1​
1​
1​
XX
1​
1​
X
1​
2​
X
Sheet: Sheet27

Formula in cell R6:
=IF(MATCH(C6,$C6:$P6,0)=COLUMNS($A$1:A1),C6,"")
 
Upvote 0
Here is a macro that should work...
Code:
Sub First1X2s()
  Dim Rw As Long
  On Error Resume Next
  Application.ScreenUpdating = False
  For Rw = 6 To Cells(Rows.Count, "C").End(xlUp).Row
    Rows(Rw).Find(1, , , xlWhole, , , , , False).Offset(, 15) = 1
    Rows(Rw).Find("X", , , xlWhole, , , , , False).Offset(, 15) = "X"
    Rows(Rw).Find(2, , , xlWhole, , , , , False).Offset(, 15) = 2
  Next
  On Error GoTo 0
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Sheet: Sheet27

<tbody>
</tbody>

Formula in cell R6:
=IF(MATCH(C6,$C6:$P6,0)=COLUMNS($A$1:A1),C6,"")
Hi Oscar Cronquist, after applying your formula I realized that in the row 62 cell AB62 my results is not correct

Your formula worked spot on

Thank you very much for your help and time

Have a nice weekend

Regards,
Kishan :)
 
Last edited:
Upvote 0
Here is a macro that should work...
Code:
Sub First1X2s()
   Dim Rw As Long
   On Error Resume Next
  Application.ScreenUpdating = False
   For Rw = 6 To Cells(Rows.Count, "C").End(xlUp).Row
     Rows(Rw).Find(1, , , xlWhole, , , , , False).Offset(, 15) = 1
     Rows(Rw).Find("X", , , xlWhole, , , , , False).Offset(, 15) = "X"
     Rows(Rw).Find(2, , , xlWhole, , , , , False).Offset(, 15) = 2
   Next
   On Error GoTo 0
   Application.ScreenUpdating = True
 End Sub
Hi Rick, result side blank, I don't get any results,

Please could you check?

Thank you

Regards,
Kishan
 
Last edited:
Upvote 0
Hi Rick, result side blank, I don't get any results,

Please could you check?

Thank you

Regards,
Kishan
Hi Rick, it worked Perfect!!

Just changed the following

This.....
Rows(Rw).Find(1, , , xlWhole, , , , , False).Offset(, 15) = 1
Rows(Rw).Find("X", , , xlWhole, , , , , False).Offset(, 15) = "X"
Rows(Rw).Find(2, , , xlWhole, , , , , False).Offset(, 15) = 2

To this....Insted 5 Comas, only 4 comas.
Rows(Rw).Find(1, , , xlW
hole, , , , False).Offset(, 15) = 1
Rows(Rw).Find("X", , , xlWhole
, , , , False).Offset(, 15) = "X"
Rows(Rw).Find(2, , , xlWhole
, , , , False).Offset(, 15) = 2

Thank you very much for your help and time

Have a nice weekend

Regards,
Kishan :)
 
Upvote 0
Hi Rick, it worked Perfect!!

Just changed the following

This.....
Rows(Rw).Find(1, , , xlWhole, , , , , False).Offset(, 15) = 1
Rows(Rw).Find("X", , , xlWhole, , , , , False).Offset(, 15) = "X"
Rows(Rw).Find(2, , , xlWhole, , , , , False).Offset(, 15) = 2

To this....Insted 5 Comas, only 4 comas.
Rows(Rw).Find(1, , , xlW
hole, , , , False).Offset(, 15) = 1
Rows(Rw).Find("X", , , xlWhole
, , , , False).Offset(, 15) = "X"
Rows(Rw).Find(2, , , xlWhole
, , , , False).Offset(, 15) = 2

Thank you very much for your help and time

Have a nice weekend

Regards,
Kishan :)
Hi Rick, may I ask you a modification #post1 "regarding the range", please can you set the search range fixed columns C:P, instead "searching data in the xlWhole Row"

Please need your help

Thank you

Regards,
Kishan
 
Upvote 0
Hi Rick, may I ask you a modification #post1 "regarding the range", please can you set the search range fixed columns C:P, instead "searching data in the xlWhole Row"

Please need your help

Thank you

Regards,
Kishan
Hi Rick, finally I could be able to modified the code with hard work many hours changing the lines with different parameters

Here is the modified code
Code:
Sub Extract_First1X2s()
  
    Sheets("Results").Select
    Range("W6:AJ5006").Select
    Selection.ClearContents
    Selection.Interior.ColorIndex = xlNone
    Selection.Font.ColorIndex = 1
    Range("W6").Select
  
  
  Dim Rw As Long
  On Error Resume Next
  Application.ScreenUpdating = False
  For Rw = 6 To Cells(Rows.Count, "B").End(xlUp).row
    Range("B" & Rw, "P" & Rw).Find(1, , , xlWhole, , , , False).Offset(, 15) = 1
    Range("B" & Rw, "P" & Rw).Find(1, , , xlWhole, , , , False).Offset(, 15).Interior.ColorIndex = 10
    Range("B" & Rw, "P" & Rw).Find(1, , , xlWhole, , , , False).Offset(, 15).Font.ColorIndex = 2
    
    Range("B" & Rw, "P" & Rw).Find("X", , , xlWhole, , , , False).Offset(, 15) = "X"
    Range("B" & Rw, "P" & Rw).Find("X", , , xlWhole, , , , False).Offset(, 15).Interior.ColorIndex = 5
    Range("B" & Rw, "P" & Rw).Find("X", , , xlWhole, , , , False).Offset(, 15).Font.ColorIndex = 2
    
    Range("B" & Rw, "P" & Rw).Find(2, , , xlWhole, , , , False).Offset(, 15) = 2
    Range("B" & Rw, "P" & Rw).Find(2, , , xlWhole, , , , False).Offset(, 15).Interior.ColorIndex = 3
    Range("B" & Rw, "P" & Rw).Find(2, , , xlWhole, , , , False).Offset(, 15).Font.ColorIndex = 2
  
  Next
  On Error GoTo 0
  Application.ScreenUpdating = True
End Sub

Thank you

Regards,
Kishan
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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