Range row Address.

H

Heera

Hi All,

I have a problem and here it is.

For example I have selected a range i.e A10:A19 in excel.

I want A10 as my start point and A19 as my end point in excel
basically I want the start row number and the end row number so that I
can write a procedure in VBA as mentioned below.

Dim Spoint as integer
Dim Epoint as integer

Spoint = 10
Epoint = 19

I tried working around with the below mentioned code but I am not able
come at a solution.

ActiveWindow.RangeSelection.Address(False, False)

Regards
Heera
 
S

Sam Wilson

Sub test()

Dim rng As Range
Set rng = Selection

Dim spt As Integer
Dim ept As Integer


spt = rng.Cells(1, 1).Row
ept = spt + rng.Rows.Count - 1

MsgBox "Starts: " & spt
MsgBox "End: " & ept

End Sub
 
R

Rob Wills

Can you not use the Range object?

Dim rng as Range

For each rng in selection
'Do whatever you want here
loop

HTH
Rob
 
B

Bernie Deitrick

Heera,

Dim Spoint As Long
Dim Epoint As Long

Spoint = Selection.Cells(1).Row
Epoint = Selection.Cells(Selection.Cells.Count).Row


Or you could simply use:

Dim myC As Range

For Each myC In Selection
'do stuff to/with myC
Next myC

HTH,
Bernie
MS Excel MVP
 

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

Top