View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default how many rows since the last time this happened

Hi,

Am Sun, 17 May 2015 01:33:24 -0700 (PDT) schrieb
:

Row number 1844 column C contains the integer 10.
I want to search back up row C (starting at row 1843) to count how many rows there are between row 1843 and the last time there was a 10 in row C.
I would prefer a solution that uses VBA.


try:

Sub Test()
Dim LRow As Long, i As Long
Dim LVal
Dim c As Range

With ActiveSheet
LRow = .Cells(Rows.Count, 3).End(xlUp).Row
LVal = .Cells(LRow, 3).Value
For i = LRow - 1 To 1 Step -1
If .Cells(i, 3) = LVal Then
MsgBox LRow - i
Exit Sub
End If
Next
End With
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional