+ Reply to Thread
Results 1 to 4 of 4

Select current selection to row 16

Hybrid View

trickyricky Select current selection to... 02-12-2011, 08:57 PM
shg Re: Select current selection... 02-12-2011, 09:35 PM
Colin Legg Re: Need help on simple macro... 02-12-2011, 09:35 PM
nimrod Re: Select current selection... 02-12-2011, 10:07 PM
  1. #1
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100

    Select current selection to row 16

    I know it's probably simple. I just need code to select the range of cells from my currently selected cell or selection up to row 16 for example.

    Thanks in advance!
    Last edited by trickyricky; 02-12-2011 at 09:55 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Select current selection to row 16

        With Selection
            Range(.Cells(1), Cells(16, .Column + .Columns.Count - 1)).Select
        End With
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Need help on simple macro to select current selection to row 16

    Hi,

    Here is a simple, logical way to do that:

    Sub foo()
        Const lngPIVOTROW As Long = 16    
        Dim lngFirstRow As Long
        Dim lngLastRow As Long
        
        If TypeOf Selection Is Range Then
            
            If Selection.Row < lngPIVOTROW Then
                lngFirstRow = Selection.Row
                lngLastRow = lngPIVOTROW
            
            ElseIf Selection.Row > lngPIVOTROW Then
                lngFirstRow = lngPIVOTROW
                lngLastRow = Selection.Row + Selection.Rows.Count - 1
                
            Else
                lngFirstRow = lngPIVOTROW
                lngLastRow = lngPIVOTROW
                
            End If
            
            Range( _
                Cells(lngFirstRow, Selection.Column), _
                Cells(lngLastRow, Selection.Column + Selection.Columns.Count - 1) _
                    ).Select
            
        End If
            
    End Sub
    But perhaps all of this is unnecessary... if you give us the big picture we might be able to suggest a better approach?
    Hope that helps,

    Colin

    RAD Excel Blog

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Select current selection to row 16

    This command will deal with 2 dimensional selections i.e. multiColumn with multiRows ( i had trouble with shg's sol'n when in came to 2 dim selections) HOWEVER... the assumption is that the selection area is below row 16.

    Union(Selection.Offset(16 - Selection.Row, 0), Selection).Select
    Last edited by nimrod; 02-12-2011 at 10:11 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1