Position of values

Starrbuckk

New Member
Joined
Mar 24, 2016
Messages
19
Hi,

I need to find the position of 2 values, lets call them "X" and "Z", on an array.
I've got a board that repeats X and Z multiple times, and what i wanted is the column position of the first time X presents itself on the Row im looking, then the first time Z presents itself on the same row, then i want the second time X presents itself again after Z, and the same thing for Z.

Ex.

XXXZZZZXXZZXX

X=1
Z=4
X=8
Z=10
X=11

So i was thinking i need some formula that changed the array according to the last position found(Array column+1/4/8) but maybe theres a simpler way.

Thanks in advance.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
If you can work with a bit of code , this may do !!
NB:- Your Data in row 1 starting "A1", Results start "A3"
Code:
[COLOR="Navy"]Sub[/COLOR] MG09May14
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, xRng [COLOR="Navy"]As[/COLOR] Range, yRng [COLOR="Navy"]As[/COLOR] Range, Rw [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] temp [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
 [COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Cells(1, Columns.Count).End(xlToLeft))
Rw = 2
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] Not Dn.Value = temp [COLOR="Navy"]Then[/COLOR]
        Rw = Rw + 1
        Cells(Rw, 1) = Dn.Value: Cells(Rw, 2) = Dn.Column
    [COLOR="Navy"]End[/COLOR] If
temp = Dn.Value
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Are they in separate columns or is it just one value like this:


Book1
AB
1XXXZZZZXXZZXX
2
314
4810
512
Sheet1
Cell Formulas
RangeFormula
A3=IFERROR(FIND("X",$A$1,B2+1),"")
B3=IFERROR(FIND("Z",$A$1,A3),"")


Separate columns like this:


Book1
ABCDEFGHIJKLM
1XXXZZZZXXZZXX
2
314
4810
512
Sheet2
Cell Formulas
RangeFormula
A3=IFERROR(MATCH("X",OFFSET($A$1:$M$1,0,B2+0),0)+B2,"")
B3=IFERROR(MATCH("Z",OFFSET($A$1:$M$1,0,A3),0)+A3,"")


WBD
 
Upvote 0
Are they in separate columns or is it just one value like this:

AB
1XXXZZZZXXZZXX
2
314
4810
512

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
A3=IFERROR(FIND("X",$A$1,B2+1),"")
B3=IFERROR(FIND("Z",$A$1,A3),"")

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



Separate columns like this:

ABCDEFGHIJKLM
1XXXZZZZXXZZXX
2
314
4810
512

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet2

Worksheet Formulas
CellFormula
A3=IFERROR(MATCH("X",OFFSET($A$1:$M$1,0,B2+0),0)+B2,"")
B3=IFERROR(MATCH("Z",OFFSET($A$1:$M$1,0,A3),0)+A3,"")

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



WBD

Thank you kind Sir,

I think i can adapt the second solution to what i need.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,835
Members
449,051
Latest member
excelquestion515

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