Consulting

Results 1 to 3 of 3

Thread: vb script to copy selection

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    vb script to copy selection

    Hi I would like to see the easiest way to do this.

    I have a list with data with 11 columns A:K.
    What I would like is for me to select a range
    example

    A5:K10 and have certain cells in columns copied over to sheet2.

    I want all the data selected copied over except for columns F of selected and in sheet2 I need 2 blank columns in between B & D Data.

    Copy Layout
    Sheet1..........Sheet2
    A -----------> A
    B -----------> B
    -------------> C ------>BLANK COLUMN
    -------------> D ------>BLANK COLUMN
    C -----------> E
    D -----------> F
    E -----------> G
    F -----------> H
    G -----------> I
    H -----------> J
    I -----------> K
    J -----------> L
    K -----------> M

    Hope this isn't too confusing.

    Thanks

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Greetings,

    Try:
    Option Explicit
        
    Sub exa()
        
        With ThisWorkbook.Worksheets("Sheet1")
            .Columns("A:E").Copy ThisWorkbook.Worksheets("Sheet2").Range("A1")
            .Columns("G:K").Copy ThisWorkbook.Worksheets("Sheet2").Range("F1")
        End With
        
        ThisWorkbook.Worksheets("Sheet2").Columns("C:D").Insert Shift:=xlToRight
    End Sub
    Hope that helps,

    Mark

  3. #3
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    Thanks for the reply GTO, but by looking at the code It looks like that will grab the entire column A:E when I would like for it to grab what's selected only. Any way it can be adjusted for that?

Posting Permissions

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