Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default First and last rows

I cannot see how to get started with this:



Having manually selected a range



typical might be B10:D25 or A77:A254



at the beginning of a macro, I need to set variables to record the first and
last rows.



So, in the case of A77:A254



FirstRow = 77

LastRow = 245



Please show me how to do this.



Francis Hookham


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,118
Default First and last rows

Since it's conceivable that you could have more than
one area selected, and the last area selected may be
above one of the other areas...

This code returns the first row of the
highest area and the last row of the lowest area:

Sub FirstLastSelRow()
Dim rArea As Range
Dim iBullpen
Dim iLastSelRow
Dim iFirstSelRow

iFirstSelRow = 10 ^ 10
iLastSelRow = 0
For Each rArea In Selection.Areas
iBullpen = rArea.Row
If iBullpen < iFirstSelRow Then
iFirstSelRow = iBullpen
End If

iBullpen = rArea.Row + rArea.Rows.Count - 1
If iBullpen iLastSelRow Then
iLastSelRow = iBullpen
End If
Next rArea
MsgBox "FirstRow: " & iFirstSelRow & " LastRow: " & iLastSelRow
End Sub

Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)


"Francis Hookham" wrote in message
...
I cannot see how to get started with this:



Having manually selected a range



typical might be B10:D25 or A77:A254



at the beginning of a macro, I need to set variables to record the first
and last rows.



So, in the case of A77:A254



FirstRow = 77

LastRow = 245



Please show me how to do this.



Francis Hookham





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default First and last rows

Thanks Ron - it will be only one range so can it be simpler?

Francis


"Ron Coderre" wrote in message
...
Since it's conceivable that you could have more than
one area selected, and the last area selected may be
above one of the other areas...

This code returns the first row of the
highest area and the last row of the lowest area:

Sub FirstLastSelRow()
Dim rArea As Range
Dim iBullpen
Dim iLastSelRow
Dim iFirstSelRow

iFirstSelRow = 10 ^ 10
iLastSelRow = 0
For Each rArea In Selection.Areas
iBullpen = rArea.Row
If iBullpen < iFirstSelRow Then
iFirstSelRow = iBullpen
End If

iBullpen = rArea.Row + rArea.Rows.Count - 1
If iBullpen iLastSelRow Then
iLastSelRow = iBullpen
End If
Next rArea
MsgBox "FirstRow: " & iFirstSelRow & " LastRow: " & iLastSelRow
End Sub

Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)


"Francis Hookham" wrote in message
...
I cannot see how to get started with this:



Having manually selected a range



typical might be B10:D25 or A77:A254



at the beginning of a macro, I need to set variables to record the first
and last rows.



So, in the case of A77:A254



FirstRow = 77

LastRow = 245



Please show me how to do this.



Francis Hookham







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,118
Default First and last rows

Sure...try this:

Sub FirstLastSelRow_1area()
Dim iLastSelRow
Dim iFirstSelRow

With Selection
iFirstSelRow = .Row
iLastSelRow = iFirstSelRow + .Rows.Count - 1
End With
MsgBox "FirstRow: " & iFirstSelRow & " LastRow: " & iLastSelRow
End Sub

Does that help?
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)




"Francis Hookham" wrote in message
...
Thanks Ron - it will be only one range so can it be simpler?

Francis


"Ron Coderre" wrote in message
...
Since it's conceivable that you could have more than
one area selected, and the last area selected may be
above one of the other areas...

This code returns the first row of the
highest area and the last row of the lowest area:

Sub FirstLastSelRow()
Dim rArea As Range
Dim iBullpen
Dim iLastSelRow
Dim iFirstSelRow

iFirstSelRow = 10 ^ 10
iLastSelRow = 0
For Each rArea In Selection.Areas
iBullpen = rArea.Row
If iBullpen < iFirstSelRow Then
iFirstSelRow = iBullpen
End If

iBullpen = rArea.Row + rArea.Rows.Count - 1
If iBullpen iLastSelRow Then
iLastSelRow = iBullpen
End If
Next rArea
MsgBox "FirstRow: " & iFirstSelRow & " LastRow: " & iLastSelRow
End Sub

Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)


"Francis Hookham" wrote in message
...
I cannot see how to get started with this:



Having manually selected a range



typical might be B10:D25 or A77:A254



at the beginning of a macro, I need to set variables to record the first
and last rows.



So, in the case of A77:A254



FirstRow = 77

LastRow = 245



Please show me how to do this.



Francis Hookham











  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default First and last rows

Exactly what I want - thank you very much.
It will be useful now and I know it will be for other occasions.

Francis

"Ron Coderre" wrote in message
...
Sure...try this:

Sub FirstLastSelRow_1area()
Dim iLastSelRow
Dim iFirstSelRow

With Selection
iFirstSelRow = .Row
iLastSelRow = iFirstSelRow + .Rows.Count - 1
End With
MsgBox "FirstRow: " & iFirstSelRow & " LastRow: " & iLastSelRow
End Sub

Does that help?
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)




"Francis Hookham" wrote in message
...
Thanks Ron - it will be only one range so can it be simpler?

Francis


"Ron Coderre" wrote in message
...
Since it's conceivable that you could have more than
one area selected, and the last area selected may be
above one of the other areas...

This code returns the first row of the
highest area and the last row of the lowest area:

Sub FirstLastSelRow()
Dim rArea As Range
Dim iBullpen
Dim iLastSelRow
Dim iFirstSelRow

iFirstSelRow = 10 ^ 10
iLastSelRow = 0
For Each rArea In Selection.Areas
iBullpen = rArea.Row
If iBullpen < iFirstSelRow Then
iFirstSelRow = iBullpen
End If

iBullpen = rArea.Row + rArea.Rows.Count - 1
If iBullpen iLastSelRow Then
iLastSelRow = iBullpen
End If
Next rArea
MsgBox "FirstRow: " & iFirstSelRow & " LastRow: " & iLastSelRow
End Sub

Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)


"Francis Hookham" wrote in message
...
I cannot see how to get started with this:



Having manually selected a range



typical might be B10:D25 or A77:A254



at the beginning of a macro, I need to set variables to record the
first
and last rows.



So, in the case of A77:A254



FirstRow = 77

LastRow = 245



Please show me how to do this.



Francis Hookham















  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,118
Default First and last rows

You're welcome, Francis.....I'm glad I could help.

Regards,

Ron
Microsoft MVP (Excel)

"Francis Hookham" wrote in message
...
Exactly what I want - thank you very much.
It will be useful now and I know it will be for other occasions.

Francis

"Ron Coderre" wrote in message
...
Sure...try this:

Sub FirstLastSelRow_1area()
Dim iLastSelRow
Dim iFirstSelRow

With Selection
iFirstSelRow = .Row
iLastSelRow = iFirstSelRow + .Rows.Count - 1
End With
MsgBox "FirstRow: " & iFirstSelRow & " LastRow: " & iLastSelRow
End Sub

Does that help?
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)




"Francis Hookham" wrote in message
...
Thanks Ron - it will be only one range so can it be simpler?

Francis


"Ron Coderre" wrote in message
...
Since it's conceivable that you could have more than
one area selected, and the last area selected may be
above one of the other areas...

This code returns the first row of the
highest area and the last row of the lowest area:

Sub FirstLastSelRow()
Dim rArea As Range
Dim iBullpen
Dim iLastSelRow
Dim iFirstSelRow

iFirstSelRow = 10 ^ 10
iLastSelRow = 0
For Each rArea In Selection.Areas
iBullpen = rArea.Row
If iBullpen < iFirstSelRow Then
iFirstSelRow = iBullpen
End If

iBullpen = rArea.Row + rArea.Rows.Count - 1
If iBullpen iLastSelRow Then
iLastSelRow = iBullpen
End If
Next rArea
MsgBox "FirstRow: " & iFirstSelRow & " LastRow: " & iLastSelRow
End Sub

Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)


"Francis Hookham" wrote in message
...
I cannot see how to get started with this:



Having manually selected a range



typical might be B10:D25 or A77:A254



at the beginning of a macro, I need to set variables to record the
first
and last rows.



So, in the case of A77:A254



FirstRow = 77

LastRow = 245



Please show me how to do this.



Francis Hookham















Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
colating multi rows of data into single rows - no to pivot tables! UKMAN Excel Worksheet Functions 4 March 12th 10 04:11 PM
Enabling option „Format rows“ to hide/unhide rows using VBA-code? ran58 Excel Discussion (Misc queries) 0 July 28th 09 03:46 PM
"Add/Remove Rows Code" adds rows on grouped sheets, but won't remove rows. Conan Kelly Excel Programming 1 November 16th 07 10:41 PM
Copy rows of data (eliminating blank rows) from fixed layout Sweepea Excel Discussion (Misc queries) 1 March 13th 07 11:05 PM
Pivot Tables: How do I show ALL field rows, including empty rows?? [email protected] Excel Worksheet Functions 2 April 8th 05 06:21 PM


All times are GMT +1. The time now is 05:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"