Find row number

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,362
Office Version
  1. 2010
Hello,

I need a row numbers of the last pairs are highlighted in the green in the range C6:E53. Formula or VBA
For examples...
Last pair 25 | 9 find in cells C47:C48 result row number i want in cell C3 = 48
Last pair 25 | H find in cells C32:C33 result row number i want in cell C3 = 33
Last pair 25 | 25 find in cells C25:C26 result row number i want in cell C3 = 26


Book1
ABCDE
125 | 925 | H25 | 25
2
3Row Nun483326
4
5n1n2n3
6HHH
7HHH
8HHH
9252525
10999
11HHH
12HHH
13999
14999
15999
16HHH
17999
18999
19999
20252525
21999
22252525
23999
24252525
25252525
26252525
27999
28252525
29HHH
30252525
31999
32252525
33HHH
34999
35HHH
36999
37999
38252525
39999
40999
41999
42252525
43999
44HHH
45252525
46999
47252525
48999
49999
50999
51HHH
52999
53252525
Sheet1


Thank you all

Excel 2000
Regards,
Moti
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
A VBA solution... In A Standard Module... (Prior to assigning the colorindex 4 inside the code from the immediate window I had to

type:
? Cells(48,3).Interior.colorindex

Where I got the numeric 4 You ought to do the same thing and make sure the two number agree...

Code:
Sub Foo()
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = 3 To 5
    For j = LR To 4 Step -1
        If Cells(j, i).Interior.ColorIndex = 4 Then
            Cells(3, i).Value = j
            Exit For
        End If
    Next j
Next i
End Sub
 
Upvote 0
A VBA solution... In A Standard Module... (Prior to assigning the colorindex 4 inside the code from the immediate window I had to

type:
? Cells(48,3).Interior.colorindex

Where I got the numeric 4 You ought to do the same thing and make sure the two number agree...

Rich (BB code):
Sub Foo()
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = 3 To 5
    For j = LR To 4 Step -1
        If Cells(j, i).Interior.ColorIndex = 4 Then
            Cells(3, i).Value = j
            Exit For
        End If
    Next j
Next i
End Sub
jim may</SPAN>

(Prior to assigning the colorindex 4 inside the code from the immediate window I had to</SPAN></SPAN>

type:
</SPAN></SPAN>
? Cells(48,3).Interior.colorindex
</SPAN></SPAN>

Where I got the numeric 4 You ought to do the same thing and make sure the two number agree...
</SPAN></SPAN>

This was a very new situation for me to understand what is a immediate window after hours searching I find how do you get the "Cells(48,3).Interior.colorindex"
</SPAN>number 4 </SPAN></SPAN>for that I required VBA as below</SPAN></SPAN></SPAN>
Code:
</SPAN></SPAN>[COLOR=#000000]
Sub find_Colour()[/COLOR]</SPAN></SPAN>[COLOR=#000000]
Debug.Print Cells(48, 3).Interior.ColorIndex[/COLOR]</SPAN></SPAN>[COLOR=#000000]
End Sub[/COLOR]</SPAN>[COLOR=#000000]
[/COLOR]
</SPAN>
I like the code idea is innovative but jim in the post#1 I filled colour to make the example clearer my question is VBA could be made with the colour usage
</SPAN></SPAN>

Thank for your help
</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Moti
</SPAN></SPAN>
 
Upvote 0
Sorry jim, there was a typo error VBA could be made without the colour usage


Re: Find row number

quote_icon.png
Originally Posted by motilulla


Sorry for my miscommunication but hopefully something was learned from the experience..
I went back to the Macro and Altered/Modified it so as to accomplish your desired GOAL.
Here it is, below. Test it out on a BACKUP Copy of your file.

Code:
Sub Foo()
Dim arr As Variant
Dim LR As Long
Dim i As Integer, j As Integer
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = 3 To 5
sLookFor = WorksheetFunction.Substitute(Cells(1, i), " ", "")
arr = Split(sLookFor, "|")
    For j = LR To 4 Step -1
        If CStr(Cells(j - 1, i).Value) = arr(0) And CStr(Cells(j, i).Value) = arr(1) Then
            Cells(3, i).Value = j
            Exit For
        End If
    Next j
Next i
End Sub
<strike></strike>




<strike></strike>
 
Upvote 0

Re: Find row number

quote_icon.png
Originally Posted by motilulla


Sorry for my miscommunication but hopefully something was learned from the experience..
I went back to the Macro and Altered/Modified it so as to accomplish your desired GOAL.
Here it is, below. Test it out on a BACKUP Copy of your file.

Code:
Sub Foo()
Dim arr As Variant
Dim LR As Long
Dim i As Integer, j As Integer
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = 3 To 5
sLookFor = WorksheetFunction.Substitute(Cells(1, i), " ", "")
arr = Split(sLookFor, "|")
    For j = LR To 4 Step -1
        If CStr(Cells(j - 1, i).Value) = arr(0) And CStr(Cells(j, i).Value) = arr(1) Then
            Cells(3, i).Value = j
            Exit For
        End If
    Next j
Next i
End Sub
<STRIKE></STRIKE>




<STRIKE></STRIKE>
jim may, thank you so much for altering the VBA, it is working as appeal (y)</SPAN></SPAN>

I appreciate your kind help. Have a good day
</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Moti :biggrin:
</SPAN></SPAN>
 
Upvote 0
Hello, Please would it be possible that VBA could worked without the conditions declared in C1:E1 as shown in the opening post (what I mean that the those conditions can be set internally in the VBA?)</SPAN></SPAN>

Regards,
</SPAN></SPAN>
Moti
</SPAN></SPAN>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,520
Members
449,088
Latest member
RandomExceller01

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