Consulting

Results 1 to 7 of 7

Thread: Multiple column select in VBA

  1. #1

    Multiple column select in VBA

    Hi Guys,

    How it can be done in VBA codes? Selecting multiple column but not in sequential.


    Thanks,
    Attached Images Attached Images

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
        Range("A1:A10,C1:C10,G1:G10").Select

  3. #3
    Thanks JKwan, another question. Can it be done by using "Range(Selection, Selection.End(xlDown)).Select"? So I will not input an specific range like A1:A10, because my data everyday have different row count.


    Quote Originally Posted by JKwan View Post
        Range("A1:A10,C1:C10,G1:G10").Select

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Sub M_snb()
       Intersect(UsedRange, Range("C:C,F:F")).Select
    End Sub

  5. #5
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    you can use snb or below
    Sub highlite()
        Dim LastRow As Long
        
        LastRow = Range("A" & Rows.Count).End(xlUp).Row
        Range("A1:A" & LastRow & ",C1:C" & LastRow & ",G1:G" & LastRow).Select
    End Sub

  6. #6
    Thanks it worked!
    Quote Originally Posted by JKwan View Post
    you can use snb or below
    Sub highlite()
        Dim LastRow As Long
        
        LastRow = Range("A" & Rows.Count).End(xlUp).Row
        Range("A1:A" & LastRow & ",C1:C" & LastRow & ",G1:G" & LastRow).Select
    End Sub
    I tried to use snb answer but it prompt
    Attached Images Attached Images

  7. #7
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Try
    Intersect(ActiveSheet.UsedRange, Range("C:C,F:F")).Select

Posting Permissions

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