How do you determine if it's the 1st row/col of a specified range?

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

Guest

Hi

Is there a piece of code that will allow me to decide whether a DummyCell is in the 1st row (or column) of a specified Range? I am interested in this as I wish to perform a special operation if it's the 1st row (or 1st column)

Thanks very much for your help!

SuperJas

-------------------------

Sub Test(

Dim DummyCell as Range, MyArea as Rang

For Each DummyCell in MyArea.Cell

<if it's the 1st row> The

............

<If it's the 1st col> The

..........

Next DummyCel

-----------------------------------------
 
Sub test()
Dim rngDummy As Range, rngMyRange As Range

Set rngDummy = Range("B5")
Set rngMyRange = Range("B2:F100")

If rngDummy.Row = rngMyRange(1).Row Then
Debug.Print "Same Row"
End If

If rngDummy.Column = rngMyRange(1).Column Then
Debug.Print "Same Column"
End If
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


SuperJas said:
Hi,

Is there a piece of code that will allow me to decide whether a DummyCell
is in the 1st row (or column) of a specified Range? I am interested in this
as I wish to perform a special operation if it's the 1st row (or 1st
column).
 
Another way is to test for intersect

For Each DummyCell In MyArea.Cells

If Not Intersect(DummyCell, MyArea.Columns(1)) Is Nothing Then
MsgBox "Cell " & DummyCell.Address & " in 1st column"
End If

If Not Intersect(DummyCell, MyArea.Rows(1)) Is Nothing Then
MsgBox "Cell " & DummyCell.Address & " in 1st row"
End If

Next DummyCell


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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