Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Code to calculate the first row and last row of a range

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
matpj - 21 Feb 2006 10:13 GMT
Hi,

in my code I need to look at a worksheet's column A and find the
occurance of a particular string.

Column A IS sorted so the string will be togther.
for example,

I'm looking for "hdw"
this occurs in rows 50-60
it is followed by a range of another string, so I need to find all rows
that contain hdw.
I wish to set a two variables.  1 to the row number of the first
instance of hdw (e.g. 50)
and the second for the last row (e.g. 60)

can anybody advise please?
thanks in advance,
Matt

Signature

matpj

Bob Phillips - 21 Feb 2006 10:32 GMT
Dim cell As Range
Dim iFirstRow As Long
Dim iLastRow As Long

   On Error Resume Next
   Set cell = ActiveSheet.Columns(1).Find("hdw", LookIn:=xlValues)
   On Error GoTo 0
   If Not cell Is Nothing Then
       iFirstRow = cell.Row
       iLastRow = iFirstRow
       Do
           iLastRow = iLastRow + 1
       Loop Until Cells(iLastRow, "A").Value <> "hdw"
       iLastRow = iLastRow - 1
   End If

Signature

HTH

Bob Phillips

(remove nothere from email address if mailing direct)

> Hi,
>
[quoted text clipped - 15 lines]
> thanks in advance,
> Matt
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.