Results 1 to 4 of 4

Thread: How to copy text from one workbook to another workbook

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    2

    How to copy text from one workbook to another workbook

    Hi,

    Can anyone tell me how to automate this in excel through a macro??

    Let me explain the whole thing to you. I have 2 excel workbooks with name as follows:
    1) rawdata.xls: it contains a rawdata in this form

    Page: 7
    Author: sullib4 Subject: Note Date: 4/13/2010 11:38:12 PM
    Break line here so that page number appears on a line with text and leaders
    Page: 17
    Author: sullib4 Subject: Comment on Text Date: 4/13/2010 11:42:11 PM
    normal, no italic
    Author: sullib4 Subject: Replacement Text Date: 4/13/2010 11:41:57 PM
    systems
    Page: 19
    Author: sullib4 Subject: Cross-Out Date: 4/13/2010 11:43:01 PM
    Author: sullib4 Subject: Inserted Text Date: 4/13/2010 11:43:22 PM
    insert a space here
    Page: 22
    Author: sullib4 Subject: Pencil Date: 4/13/2010 11:44:35 PM
    Author: sullib4 Subject: Pencil Date: 4/13/2010 11:44:30 PM
    Author: sullib4 Subject: Inserted Text Date: 4/14/2010 12:35:21 AM
    the
    Author: sullib4 Subject: Inserted Text Date: 4/14/2010 12:35:47 AM
    insert a registered trademark here
    Page: 23
    Author: sullib4 Subject: Pencil Date: 4/13/2010 11:48:48 PM
    Author: sullib4 Subject: Pencil Date: 4/13/2010 11:48:40 PM
    Author: sullib4 Subject: Pencil Date: 4/13/2010 11:49:55 PM
    Author: sullib4 Subject: Pencil Date: 4/13/2010 11:49:42 PM
    Author: sullib4 Subject: Pencil Date: 4/13/2010 11:49:50 PM
    Author: sullib4 Subject: Pencil Date: 4/13/2010 11:51:41 PM
    Author: sullib4 Subject: Replacement Text Date: 4/13/2010 11:52:38 PM
    Model and quantity
    Author: sullib4 Subject: Inserted Text Date: 4/13/2010 11:55:55 PM
    Optional
    Author: sullib4 Subject: Pencil Date: 4/13/2010 11:50:59 PM
    Author: sullib4 Subject: Pencil Date: 4/13/2010 11:56:20 PM

    2) Table.xls: Its has a table with the following 4 headings and columns:

    Page Number
    Type of Comment
    Commenter
    Comment Description

    What exactly I want this macro to do is:

    1) It should copy the page number( from rawdata.xls) and paste it to the 'PAGE NUMBER' column ( in Table.xls).
    2) Next, It should copy all the rows that starts with the word 'Author' under above Page number heading (from rawdata.xls) and paste it to the 'TYPE OF COMMENT' column ( in Table.xls).
    3) Next, It should copy all the rows that does not starts with the word 'Author' under above Page number heading (from rawdata.xls) and paste it to the 'COMMENT DISCRIPTION' column ( in Table.xls).
    4) It should repeat the same for each and every Page Number.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to copy text from one workbook to another workbook

    show an image of the result for the above data
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    2

    Re: How to copy text from one workbook to another workbook

    Thanks for replying Pete! Here is the picture of the desired result in a attachment:
    Attached Images Attached Images  

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to copy text from one workbook to another workbook

    from the image it would appear that all the authors and comments are in a single row for each page, this may be incorrect
    vb Code:
    1. Set raw = Workbooks("rawdata.xls").Sheets("sheet1")
    2. Set tabl = workbooks("table.xls").Sheets("sheet1")
    3. myrow = 3  ' starting row
    4. For Each c In raw.Range("a1:a99")    ' change range to suit
    5.     If InStr(c, "Page:") > 0 Then
    6.         tabl.Cells(myrow, 1) = c
    7.         tabl.Cells(myrow - 1, 2) = myauth: myauth = ""
    8.         tabl.Cells(myrow - 1, 4) = mycomnt: mycomnt = ""
    9.         myrow = myrow + 1
    10.         ElseIf InStr(c, "Author:") > 0 Then myauth = myauth & c & vbNewLine
    11.         Else: mycomnt = mycomnt = mycomnt & c & vbNewLine
    12.     End If
    13. Next
    14. tabl.Cells(myrow, 2) = myauth: myauth = ""
    15. tabl.Cells(myrow, 4) = mycomnt: mycomnt = ""
    not tested, if the authors and comments should be on individual rows, some modifications would be required, change sheet names to suit
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width