Copy data from a workbook and paste values into another workbook

racheltaylor

New Member
Joined
Aug 10, 2013
Messages
7
Hi

I need to copy and paste the values of certain columns from one workbook to different columns in another workbook. See my code below..
I know this code is not efficient, I am new to VBA and would appreciate any help to make my macro more efficient..
I could start copying from row 2 instead of 1, however the end of the range is variable and includes blank cells and I am not sure how to reflect this in my code..:confused:


Sub CopyDataToCombinedRegister()


Dim Obook As Workbook
Dim DBook As Workbook


Set Obook = workbooks("General Checks.xlsm")
Set DBook = workbooks("Aged & General Checks V10.xlsx")


Dim wsd As Worksheet
Dim wsc As Worksheet


Set wsd = workbooks("Test.xlsm").Worksheets("sheet1")
Set wsc = workbooks("Aged & General Checks V10 25.01.11test (1).xlsx").Worksheets("sheet1")


wsd.Activate


Range("A:A").Select
Selection.Copy
wsc.Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues

wsd.Activate
Range("E:E,F:F,G:G").Select
Selection.Copy
wsc.Activate
Range("D1").Select
Selection.PasteSpecial Paste:=xlPasteValues

wsd.Activate
Range("L:L").Select
Selection.Copy
wsc.Activate
Range("K1").Select
Selection.PasteSpecial Paste:=xlPasteValues

wsd.Activate
Range("U:U,V:V,W:W").Select
Selection.Copy

wsc.Activate
Range("L1").Activate
Selection.PasteSpecial Paste:=xlPasteValues


End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I also know it's not necessary to activate sheets continuously like I have done..
basically I need the below

Column "A" to be copy pasted to column "A"
Columns "E, F, G" to copy pasted to columns "D, E, F" (in that order)
Column "L" to be copy pasted to column "K"
Columns "U, V, W" to be copy pasted to columns "L, M, N" (in that order"

I am copying columns because the range is variable and I'm not sure how to define this.. i.e. Data in column A actually starts in row two, the range contains blanks (as do some but not all of my ranges) and the last cell to the range is variable...because blanks are included in the range i'm not sure how to write a code that includes the blanks....hence the copying of the entire column..

Any help with this is much appreciated!
 
Upvote 0

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top