What does this parameter mean?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My macro appears as follows

Dim r As Range, c As Range

Set r = Range(Range("B4"), Range("B4").End(xlDown))
Set c = r.Find("NA", SearchDirection:=xlPrevious)(2)
If Not c Is Nothing Then
Set r = Range(c, c.End(xlDown))
Range("D4").Resize(r.Count).Value = r.Value
End If

My question is based on the following line

Set c = r.Find("NA", SearchDirection:=xlPrevious)(2)

What does the (2) at the end of the line mean?

Thank you
 
Hi ManKind,
My question is based on the following line
Set c = r.Find("NA", SearchDirection:=xlPrevious)(2)
What does the (2) at the end of the line mean?


This line of code is an abbreviation for:

Set c = r.Find("NA", SearchDirection:=xlPrevious).Item(2,1)

and is equivalent to:

Set c = r.Find("NA", SearchDirection:=xlPrevious).Offset(1,0)

For a detailed discussion of this, Chip Pearson hosts an excellent article,
written by Alan Beban:

http://www.cpearson.com/excel/cells.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top