LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Still stuck on finding the last occurence...thanks...

Hi, the code below is as far as I have got (courtesy of this ng). I
asked a question similar
to this a few days ago, and with help have arrived to this point.

By testing it with msg box's it seems to be doing what it is supposed
to for the most part.
It is supposed to find the last occurence in the range on sheet
'BaseData' of a value =
minValue and <=maxValue, and pass the row number the value was found on
to another
sheet named 'Main'. Thats it, all that is required is the row number of
the last occurence.

I am almost sure the code is stepping backwards through the range on
sheet 'BaseData' but
does not seem to start stepping backwards from 'LastRow' but from row
6!...gggaaaaaarrrrhhhhh.....

Can anybody see what I've done wrong? Have I gone the wrong way about
it?

cheers

ste

Sub aaa()
Application.ScreenUpdating = False

Dim DataRng As Range
Dim r As Integer
Dim LastRow As Long
Dim minValue As Long
Dim maxValue As Long

minValue = Sheets("Main").Range("I" & Rows.Count).End(xlUp).Value
maxValue = Sheets("Main").Range("J" & Rows.Count).End(xlUp).Value

LastRow = Sheets("BaseData").Cells(Rows.Count, "B").End(xlUp).Row

Set DataRng = Sheets("BaseData").Range("B2:U" & LastRow)

For r = LastRow To 2 Step -1

If DataRng(r) = minValue And DataRng(r) <= maxValue Then
Sheets("Main").Range("L65536").End(xlUp).Offset(1, 0).Value
= r
End If

Next r

Application.ScreenUpdating = True
End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding last occurence of Interior.ColorIndex 36 Linda New Users to Excel 2 May 28th 10 07:04 AM
Finding first occurence of a number beginner here Excel Worksheet Functions 10 November 28th 07 01:17 AM
Finding how many events since last occurence in a database list Tony the Bajan Excel Worksheet Functions 3 November 2nd 06 10:32 PM
Finding most common occurence of values in cells containing letters and numbers sparklyballs Excel Worksheet Functions 2 August 18th 06 12:16 PM
Occurence #'s Seveneleven Excel Discussion (Misc queries) 6 February 7th 06 07:38 PM


All times are GMT +1. The time now is 01:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"