PC Review


Reply
Thread Tools Rate Thread

dtermine row/column boundaries of selected area

 
 
John Keith
Guest
Posts: n/a
 
      2nd Jun 2009
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
(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      2nd Jun 2009
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
> (E-Mail Removed)
>

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      2nd Jun 2009
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
> (E-Mail Removed)
>

 
Reply With Quote
 
John Keith
Guest
Posts: n/a
 
      2nd Jun 2009
On Tue, 2 Jun 2009 09:09:07 -0700, Gary''s Student
<(E-Mail Removed)> 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
(E-Mail Removed)
 
Reply With Quote
 
John Keith
Guest
Posts: n/a
 
      3rd Jun 2009
On Tue, 2 Jun 2009 09:30:01 -0700, Mike H
<(E-Mail Removed)> 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
(E-Mail Removed)
 
Reply With Quote
 
John Keith
Guest
Posts: n/a
 
      3rd Jun 2009
On Tue, 2 Jun 2009 09:09:07 -0700, Gary''s Student
<(E-Mail Removed)> 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
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing selected area Nunya Microsoft Excel Misc 1 6th Feb 2008 07:16 PM
Worksheet Row/Column Boundaries Question =?Utf-8?B?c2NvdHR5ZGVs?= Microsoft Excel Programming 3 27th Jul 2007 08:56 PM
Import excel but selected column for selected table EMILYTAN via AccessMonster.com Microsoft Access Form Coding 4 15th May 2007 03:27 AM
can't dtermine the problem kaspr79 Computer Hardware 4 9th Jun 2006 08:58 PM
Dtermine the Period =?Utf-8?B?RXJpYw==?= Microsoft Access VBA Modules 2 4th Feb 2005 05:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:37 PM.