Results 1 to 3 of 3

Thread: [RESOLVED] Working with Selected Rows Only??

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    17

    Resolved [RESOLVED] Working with Selected Rows Only??

    I'm trying to get my macro to act on the selected rows only, as compared to running through all rows from top to bottom. Is there a way to check the status of the row as the activecell moves down the spreadsheet? If not selected then go to next row and check again. THANKS.

    For example:

    Sub Loop_Selected_Rows()

    Range("A1").Select

    For x = 1 To NumRows

    ActiveCell.Offset(1, 0).Activate
    ' I assumed using .select would unselect the selected rows. Not sure if activate would work

    'If row is selected Then
    ' do stuff here
    'End If

    Next x

    End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Working with Selected Rows Only??

    Yes, the .Activate will also deselect any rows that have been selected.
    You can have only one, either a selection or an active cell at a time.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    17

    Re: [RESOLVED] Working with Selected Rows Only??

    Found a way around it!! Here:

    Private Sub Run_Selected_Info()

    i = 1
    x = 1

    Dim RowArray(1000) As Integer

    For Each RW In Selection.Rows
    RowArray(i) = RW.Row
    i = i + 1
    Next RW

    Do While RowArray(x) <> 0
    Cells(RowArray(x), 1).Select
    ' Call some function here
    x = x + 1
    Loop

    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width