Sub test2()
inarr = Range(Cells(1, 1), Cells(5, 5))
Range(Cells(1, 10), Cells(30, 11)) = ""
outarr = Range(Cells(1, 10), Cells(30, 11))
indi = 1
For i = 2 To 5
For j = 2 To 5
If inarr(i, j) = "x" Then
outarr(indi, 1) = inarr(i, 1)
outarr(indi, 2) = inarr(1, j)
indi = indi + 1
End If
Next j
Next i
Range(Cells(1, 10), Cells(30, 11)) = outarr
End Sub
Thank you. I suppose that the result can not be achieved by an Ecel formula only?this should do it:
Code:Sub test2() inarr = Range(Cells(1, 1), Cells(5, 5)) Range(Cells(1, 10), Cells(30, 11)) = "" outarr = Range(Cells(1, 10), Cells(30, 11)) indi = 1 For i = 2 To 5 For j = 2 To 5 If inarr(i, j) = "x" Then outarr(indi, 1) = inarr(i, 1) outarr(indi, 2) = inarr(1, j) indi = indi + 1 End If Next j Next i Range(Cells(1, 10), Cells(30, 11)) = outarr End Sub
ADVERTISEMENT
A | B | C | D | E | F | |
1 | A | B | C | D | ||
2 | 1 | x | x | |||
3 | 2 | x | x | x | ||
4 | 3 | |||||
5 | 4 | x | x | |||
6 | ||||||
7 | Desired Result: | |||||
8 | 1 | A | ||||
9 | 1 | B | ||||
10 | 2 | B | ||||
11 | 2 | C | ||||
12 | 2 | D | ||||
13 | 4 | A | ||||
14 | 4 | D | ||||
15 |