Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default dtermine row/column boundaries of selected area

After a user has selected an area on a worksheet I need to have a
macro determine the top and bottom row boundaries and the left and
right column boundaries of the range. How is this accomplished in a
macro?

Thanks


John Keith

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default dtermine row/column boundaries of selected area

This works well if the Selection is a nice block:

' this routine gives the limits of a range
' first & last row & column
' number of rows and columns
' the address of the range
' the address of the first cell in the range
' the worksheet of the range
' the workbook of the range
' count of cells
Sub range_reporter()
Dim r As Range
Dim s As String
Set r = Selection

nLastRow = r.Rows.Count + r.Row - 1
MsgBox ("last row " & nLastRow)

nLastColumn = r.Columns.Count + r.Column - 1
MsgBox ("last column " & nLastColumn)

nFirstRow = r.Row
MsgBox ("first row " & nFirstRow)

nFirstColumn = r.Column
MsgBox ("first column " & nFirstColumn)

numrow = r.Rows.Count
MsgBox ("number of rows " & numrow)

numcol = r.Columns.Count
MsgBox ("number of columns " & numcol)

s = r.Address
MsgBox ("address " & s)

s = r(1).Address
MsgBox ("address of first cell " & s)
MsgBox ("worksheet " & r.Worksheet.Name)

MsgBox ("workbook " & r.Worksheet.Parent.Name)

MsgBox ("item count " & r.Count)
End Sub
--
Gary''s Student - gsnu200855


"John Keith" wrote:

After a user has selected an area on a worksheet I need to have a
macro determine the top and bottom row boundaries and the left and
right column boundaries of the range. How is this accomplished in a
macro?

Thanks


John Keith


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default dtermine row/column boundaries of selected area

On Tue, 2 Jun 2009 09:09:07 -0700, Gary''s Student
wrote:

This works well if the Selection is a nice block:

Good clarification! It is a "nice" block that I am expecting from the
selection.

Thanks fo rthe quick reply, I'm off and running now.



John Keith

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default dtermine row/column boundaries of selected area

On Tue, 2 Jun 2009 09:09:07 -0700, Gary''s Student
wrote:

This works well if the Selection is a nice block:

' the worksheet of the range
' the workbook of the range
' count of cells


The comments at the start of the sample code suggested the worksheet,
workbook and cell count can be found but were not inlcuded in the
code. What is the correct structure to get that info?


John Keith

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default dtermine row/column boundaries of selected area

Try

Sub Sonic()
FRow = Selection(1).Row
FCol = Selection(1).Column
LRow = FRow + Selection.Rows.Count - 1
LColumn = FCol + Selection.Columns.Count - 1

LRow = Selection(Selection.Cells.Count).Row
LColumn = Selection(Selection.Cells.Count).Column
MsgBox LColumn
MsgBox LRow
MsgBox FCol
MsgBox FRow
End Sub

Mike

"John Keith" wrote:

After a user has selected an area on a worksheet I need to have a
macro determine the top and bottom row boundaries and the left and
right column boundaries of the range. How is this accomplished in a
macro?

Thanks


John Keith




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default dtermine row/column boundaries of selected area

On Tue, 2 Jun 2009 09:30:01 -0700, Mike H
wrote:

Try

Sub Sonic()
FRow = Selection(1).Row
FCol = Selection(1).Column
LRow = FRow + Selection.Rows.Count - 1
LColumn = FCol + Selection.Columns.Count - 1



That looks cool too!

I learn so much in this group, I wish I had time to read every thread!


John Keith

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
Highlight selected area dkallen Excel Discussion (Misc queries) 4 September 12th 07 04:52 PM
Worksheet Row/Column Boundaries Question scottydel Excel Programming 3 July 27th 07 08:56 PM
Need VBA code to dtermine how many rows have data in them Shani Excel Programming 4 April 13th 06 05:17 PM
Capitalizing selected area J.E Excel Discussion (Misc queries) 3 March 30th 05 10:10 PM
Retaining Selected area Elaine Excel Programming 2 March 10th 05 06:15 PM


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

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

About Us

"It's about Microsoft Excel"