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]
 

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,078,499
Messages
5,340,740
Members
399,393
Latest member
farlow

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top