View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Find in a dynamic column...

Sorry about that. Without qualifying the worksheet, it will run on the
active sheet. I should have done that, but I assumed you were either working
w/the active sheet or you were familiar w/fully qualifying the range.


With Worksheets("Sheet1")
Set ytdRng = .Range(levelrng, .Cells(.Rows.Count, levelrng.Column).End(xlUp))
.Find(What:=prevName, _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
End With

or use the Parent property of levelrng
With levelrng.Parent
Set ytdRng = .Range(levelrng, .Cells(.Rows.Count, levelrng.Column).End(xlUp))
.Find(What:=prevName, _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
End With


"billboe" wrote:

JMB wrote:
If levelrng is not in the first row you'll get an error using
levelrng.range("a65536"). I know the OP states he is using a fixed range of
A1:A1000, but his code indicates this range is relative to levelrng.

Just in case levelrng might not be in row 1:
Range(levelrng, Cells(Rows.Count, levelrng.Column).End(xlUp))


Thanks to you both for your responses! JMB was correct, levelrng was
not in the 1st row... However, I had a heck of a time to get this
running... I finally figured out that the sheet needed be activated
for it to work. At least, that is what made it work for me... Does
that make sense!?!?


Thanks again!!!

Bill