+ Reply to Thread
Results 1 to 15 of 15

Macro to transpose data from Excel to Word

Hybrid View

  1. #1
    Registered User
    Join Date
    07-18-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    7

    Macro to transpose data from Excel to Word

    Hello! I'm an intern at a company and I need help with a problem I'm having.

    I need to create a macro to copy a row of cells from an Excel spreadsheet to a Word template.

    Ideally, the macro would work like this.

    1. The user highlights a row of cells.
    2. The row of data has cells that fall under different categories defined by the columns they are in.
    3. The macro would then paste the cells to corresponding locations in the Word template.

    Can anyone give me an example on how to do this?
    Or link me to some literature that can help me?

    Thank you in advance. I would appreciate any help greatly.

    I have attached examples for reference.

    Thanks any help is greatly appreciated!
    Attached Files Attached Files
    Last edited by Wendy_The_Intern_<3; 07-18-2011 at 05:21 PM.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to transpose data from Excel to Word.

    one of the ways to make that, please check .xls attachment. The attached word file must be saved here: C:\forumexamle.doc or you may change it to any path of yours in the code. Select A:K Excel range and run code "test".
    Attached Files Attached Files

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro to transpose data from Excel to Word.

    Hello Wendy_The_Intern_<3,

    Welcome to the Forum!

    Can you provide a list that shows which column on Sheet1 corresponds to which label in the Word document?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    07-18-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Macro to transpose data from Excel to Word.

    Hello Leith!

    Thank you so much for helping me! You don't know how much I appreciate it

    Column A --> !JOB
    Column B --> !SHIPPER
    Column C--> !DATECREATED
    Column D--> !CUSTOMER
    Column E--> !FANALYST
    Column F--> !COUNT
    Column G--> N/A (Not Applicable)
    Column H--> !DEVNUM
    Column I--> !LOT
    Column J--> N/A
    Column K-->!DATECOMPLETE
    Column L--> N/A (Not Applicable)

    Thank you! You're great!

    Btw, I updated the attachments so be sure you open the new ones! Thanks!
    Last edited by Wendy_The_Intern_<3; 07-18-2011 at 05:42 PM. Reason: update

  5. #5
    Registered User
    Join Date
    07-18-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Macro to transpose data from Excel to Word.

    bump for me

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro to transpose data from Excel to Word.

    Hello Wndy,

    You have this field !PARTTYPEs in the Word document but I don't see a column for it on the Excel worksheet. Should I ignore it?

    EDIT: These fields are missing in excel also - !WORDNUM and !HOURS
    Last edited by Leith Ross; 07-19-2011 at 04:37 PM. Reason: Found more missing fields

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro to transpose data from Excel to Word.

    See the attachments

    copy te worddocument to your own location. you have to adapt the code to find it (see below)

    Open the Excel Workbook
    Select a cell in a certain row you want to be transpoerted en run the macro:

    Before running the macro you have to change "E:\OF\" in the macro by the path wheree de Worddocument is located.

    Sub snb()
      sn = Cells(ActiveCell.Row, 1).Resize(, 11)
        
      With GetObject("E:\OF\forumexample wendy.doc")
        .variables("wordnum") = " "
        .variables("hours") = " "
        For j = 1 To UBound(sn, 2)
          If j <> 10 Then .variables(Choose(j, "job", "shipper", "datecreated", "customer", "fanalyst", "count", "parttypes", "devnum", "lot", "", "datecomplete")) = IIf(sn(1, j) = "", " ", sn(1, j))
        Next
        .Activate
        .fields.Update
        .SaveAs "E:\OF\form 001.doc"
        .Close
      End With
    End Sub
    Attached Files Attached Files



  8. #8
    Registered User
    Join Date
    07-18-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Macro to transpose data from Excel to Word.

    Thank you guys so much for replying!

    I tried both of the codes and they don't seem to be working.
    I've changed the path code on both codes to where my doc is.
    But the data doesn't seem to be copying over.

    I debugged it and when I followed what the program did, it seems that it's not copying.

    Anyone know what's going on?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1