PDA

View Full Version : vb script to copy selection



Emoncada
01-14-2010, 10:08 AM
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

GTO
01-14-2010, 11:36 PM
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

Emoncada
01-15-2010, 09:34 AM
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?