Copy & paste from specific columns from one workbook to another

rubic

Active Member
Joined
Jul 9, 2008
Messages
251
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11"><link rel="File-List" href="file:///C:%5CDOCUME%7E1%5Candy.tan%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->[FONT=&quot]Trying out myself to write some codes but having problem to solve this one.
I am trying to copy for a source workbook from a sheet(sheet1) to the target workbook sheet (WP2407) if rows in Column A contain a specific value = WP2407. Secondly, I only want data from Column A to F and S and T from source file.[/FONT]
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
See my answer to yournext post. However, even thought it's an easy solution for your problem, it doesn't answer your request for code. Perhaps you can use the logic in my solution to produce your code.

You can also recor a macro doing what I suggest, and stop recording. Then, you can look at the code created, and modifiy it for future work of the kind you need.
 
Upvote 0
Hi, You can try:

Workbooks("xxxxx").sheets("WP2407").activate 'Target
x=2

With Workbooks("xxxxx").Worksheets("sheet1").Range("A:A") 'Source file
Set c = .Find("WP2407", lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
A= c.offset(0,0).Value 'Value in Column A
F= c.offset(0,5).Value
S= c.offset(0,18).Value
T= c.offset(0,19).Value

range("A" & x).value = A
range("B" & x).value = F
range("C" & x).value = S
range("D" & x).value = T

Set c = .FindNext(c)
x=x+1
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
 
Upvote 0
Say, alvinwlh, is your sentence,
If Not c Is Nothing Then
the equivalent of
If c <> "" and c <> 0 Then

I'm just curious, as I don't really do VBA, only BASIC and QuickBASIC.
 
Upvote 0
Hi RalphA,

I am also very new in VBA. But I think it is just If c.value <> "" then
This is copied from VBA help under find method.
 
Upvote 0

Forum statistics

Threads
1,214,384
Messages
6,119,201
Members
448,874
Latest member
Lancelots

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