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]
 

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

RalphA

Well-known Member
Joined
May 14, 2003
Messages
3,829
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.
 

alvinwlh

Active Member
Joined
Feb 16, 2009
Messages
305
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
 

RalphA

Well-known Member
Joined
May 14, 2003
Messages
3,829
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.
 

alvinwlh

Active Member
Joined
Feb 16, 2009
Messages
305
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.
 

Forum statistics

Threads
1,089,225
Messages
5,406,956
Members
403,113
Latest member
ms_excel_recal_or_die

This Week's Hot Topics

Top