ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do you determine if it's the 1st row/col of a specified range? (https://www.excelbanter.com/excel-programming/294400-how-do-you-determine-if-its-1st-row-col-specified-range.html)

SuperJas

How do you determine if it's the 1st row/col of a specified range?
 
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

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

Rob van Gelder[_4_]

How do you determine if it's the 1st row/col of a specified range?
 
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" wrote in message
...
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 Range

For Each DummyCell in MyArea.Cells

<if it's the 1st row Then

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

<If it's the 1st col Then

...........

Next DummyCell

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




Bob Phillips[_6_]

How do you determine if it's the 1st row/col of a specified range?
 
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)

"Rob van Gelder" wrote in message
...
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" wrote in message
...
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 Range

For Each DummyCell in MyArea.Cells

<if it's the 1st row Then

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

<If it's the 1st col Then

...........

Next DummyCell

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







All times are GMT +1. The time now is 03:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com