Excel: Determine extent of current selection 
Author Message
 Excel: Determine extent of current selection

Hi,

I have a script that operates on a the user's selection. If they select a
finite number of cells, I am fine. But if they click up in the corner to
select the entire worksheet, my function runs forever on the empty cells.

How can I determine if the selection is mostly real data, or includes all of
the blank cells?

Here is the gist of my code:

    Dim iStartRow
    Dim iStartColumn
    Dim iCurrentRow
    Dim iCurrentColumn
    Dim iEndRow
    Dim iEndColumn

    Dim strCurrentText

    iStartRow = Selection.Row
    iStartColumn = Selection.Column
    iEndRow = Selection.Rows.Count + iStartRow - 1
    iEndColumn = (Selection.Columns.Count + iStartColumn) - 1

    For iCurrentColumn = iStartColumn To iEndColumn
        For iCurrentRow = iStartRow To iEndRow
            ' Do some work on the current cell, based on it's contents
            '  So, we can't just work on the section instead...
        Next iCurrentRow
    Next iCurrentColumn

Thanks!



Tue, 21 Jun 2005 06:54:45 GMT  
 Excel: Determine extent of current selection
There is a property of the worksheet that defines the extent of the selectable content (e.g. not forever ad infinitum).

I can't remember the name of it cos it was yonks ago that I did something like this.

Have a look in the VBA help - if I find it in the meantime I will post back.

Chris Barber.

Hi,

I have a script that operates on a the user's selection. If they select a
finite number of cells, I am fine. But if they click up in the corner to
select the entire worksheet, my function runs forever on the empty cells.

How can I determine if the selection is mostly real data, or includes all of
the blank cells?

Here is the gist of my code:

    Dim iStartRow
    Dim iStartColumn
    Dim iCurrentRow
    Dim iCurrentColumn
    Dim iEndRow
    Dim iEndColumn

    Dim strCurrentText

    iStartRow = Selection.Row
    iStartColumn = Selection.Column
    iEndRow = Selection.Rows.Count + iStartRow - 1
    iEndColumn = (Selection.Columns.Count + iStartColumn) - 1

    For iCurrentColumn = iStartColumn To iEndColumn
        For iCurrentRow = iStartRow To iEndRow
            ' Do some work on the current cell, based on it's contents
            '  So, we can't just work on the section instead...
        Next iCurrentRow
    Next iCurrentColumn

Thanks!



Tue, 21 Jun 2005 07:53:09 GMT  
 Excel: Determine extent of current selection
Ah ha - found it - I think!

Pasted from help.
UsedRange Property
Returns a Range object that represents the used range on the specified worksheet. Read-only.

This example selects the used range on Sheet1.

Worksheets("Sheet1").Activate
ActiveSheet.UsedRange.SelectChris.

Hi,

I have a script that operates on a the user's selection. If they select a
finite number of cells, I am fine. But if they click up in the corner to
select the entire worksheet, my function runs forever on the empty cells.

How can I determine if the selection is mostly real data, or includes all of
the blank cells?

Here is the gist of my code:

    Dim iStartRow
    Dim iStartColumn
    Dim iCurrentRow
    Dim iCurrentColumn
    Dim iEndRow
    Dim iEndColumn

    Dim strCurrentText

    iStartRow = Selection.Row
    iStartColumn = Selection.Column
    iEndRow = Selection.Rows.Count + iStartRow - 1
    iEndColumn = (Selection.Columns.Count + iStartColumn) - 1

    For iCurrentColumn = iStartColumn To iEndColumn
        For iCurrentRow = iStartRow To iEndRow
            ' Do some work on the current cell, based on it's contents
            '  So, we can't just work on the section instead...
        Next iCurrentRow
    Next iCurrentColumn

Thanks!



Tue, 21 Jun 2005 07:58:04 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Determine PS File Extents: Incorrect Bounding Box

2. Clarification of question: How do I determine current URL from an external file/program

3. determining the current url in a frame

4. Determining if current page is not last item in history list

5. Current folder : How determine ?

6. Determining the current drive

7. Determine current line number in textarea

8. How do I determine current WSH version?

9. Determine Current Directory?

10. Determining current directory

11. How can I determine the current directory?

12. Getting the Current Time-Selection from Outlook 2002 Calendar

 

 
Powered by phpBB® Forum Software