Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code to calculate the first row and last row of a range


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


--
matpj
------------------------------------------------------------------------
matpj's Profile: http://www.excelforum.com/member.php...o&userid=21076
View this thread: http://www.excelforum.com/showthread...hreadid=514818

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Code to calculate the first row and last row of a range

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


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"matpj" wrote in
message ...

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


--
matpj
------------------------------------------------------------------------
matpj's Profile:

http://www.excelforum.com/member.php...o&userid=21076
View this thread: http://www.excelforum.com/showthread...hreadid=514818



Reply
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
Calculate with code Chey Excel Discussion (Misc queries) 2 December 29th 07 12:01 AM
Using code to calculate a value in the next row Barth Wilsey Excel Programming 2 December 4th 03 03:08 PM
VBA code to calculate the difference between rows desmond Excel Programming 0 July 28th 03 08:25 PM
VBA code to calculate the difference between rows Alan Beban[_3_] Excel Programming 0 July 28th 03 04:39 AM
VBA code to calculate the difference between rows John Green[_2_] Excel Programming 0 July 28th 03 03:29 AM


All times are GMT +1. The time now is 12:12 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"