Help modifying Macro to pull columns

Itried

New Member
Joined
Jul 27, 2015
Messages
22
Hi,

I currently have this Macro which opens up a diff workbook and pulls three columns from it onto the current workbook. However it is not functioning properly it is only pulling column J and pasting those same values into columns A-C on the current sheet.

This is my code:

Sub database()
Dim wbA As Workbook, wbB As Workbook


Set wbA = ThisWorkbook
Set wbB = Workbooks.Open("Z:\snv_pfm_commdrive\Sprint PFM\Mir Ali\Excluded Fees Sprint Report Data Through 150723.xlsx")


wbB.Activate
Target_Data = wbB.Sheets(4).Range("$J:$J,$Q:$Q,$AS:$AS").EntireColumn
wbA.Sheets(3).Range("$A:$A,$B:$B,$C:$C") = Target_Data


Source_data = wbA.Sheets(3).Range("$A:$A,$B:$B,$C:$C")


wbB.Close
wbA.Save
End Sub

Any help would be appreciated!!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You might have better luck with this method.
Code:
Dim rng As Range
With Sheets(4)
    Set rng = Union(.Range("$J:$J"), .Range("$Q:$Q"), .Range("$AS:$AS"))
    rng.Copy wbA.Sheets(3).Range("$A1")
    Source_data = wbA.Sheets(3).Range("$A:$A,$B:$B,$C:$C")
End With
but your Source_data variable could be problematic. Not quite sure what you are trying to do with it.
 
Upvote 0
You might have better luck with this method.
Code:
Dim rng As Range
With Sheets(4)
    Set rng = Union(.Range("$J:$J"), .Range("$Q:$Q"), .Range("$AS:$AS"))
    rng.Copy wbA.Sheets(3).Range("$A1")
    Source_data = wbA.Sheets(3).Range("$A:$A,$B:$B,$C:$C")
End With
but your Source_data variable could be problematic. Not quite sure what you are trying to do with it.

I think I might have just left that Source_data variable from all the other ways I tried to make this code.

But yes, this worked perfectly! Thank you so much!!
 
Upvote 0
I think I might have just left that Source_data variable from all the other ways I tried to make this code.

But yes, this worked perfectly! Thank you so much!!

You're welcome,
Regards, JLG
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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