Results 1 to 2 of 2

Thread: [RESOLVED] Selecting nonAdjacent Cells?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    13

    Resolved [RESOLVED] Selecting nonAdjacent Cells?

    I see from the macro recorder that nonadjacent cells can be selected simultaneously like this:

    Range("G17,J34,N19").Select

    How can I do this using integers? Range(cells(x,y),cells(i,j)).Select selects an entire region (correct my vocab if incorrect please) and Range(cells(x,y),cells(i,j),cells(a,b)).Select produces a syntax error...

    Thanks
    Last edited by davidd31415; Nov 22nd, 2005 at 09:33 PM.

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Selecting nonAdjacent Cells?

    Use the Union method of the Excel application.

    Example

    VB Code:
    1. Sub DavidRange()
    2. Dim DaveRange As Range
    3. Dim DaveCell As Range
    4.    
    5.     Set DaveRange = Worksheets(1).Cells(1, 1)
    6.     Set DaveRange = Application.Union(DaveRange, Worksheets(1).Cells(2, 2))
    7.     Set DaveRange = Application.Union(DaveRange, Worksheets(1).Cells(4, 10))
    8.     'etc....
    9.    
    10.     For Each DaveCell In DaveRange.Cells
    11.         Debug.Print DaveCell.Address
    12.     Next DaveCell
    13. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

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