+ Reply to Thread
Results 1 to 15 of 15

Macro to transpose data from Excel to Word

  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 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!)

  3. #3
    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

  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.

    bump for me

  5. #5
    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

  6. #6
    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

  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.

    Please Login or Register  to view this content.
    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?

  9. #9
    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 Libby,

    If you can provide me with answers to my previous post then I can finish the macro for you.

  10. #10
    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.

    I hope you did realise that the result will be saved in the document 'form 001.doc'

    In the attachment a workbook in which you won't need to change anything, provided you store this workbook in the same folder as that containing the worddocument.
    You only have to run the macro:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by snb; 07-20-2011 at 01:22 PM.

  11. #11
    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.

    Quote Originally Posted by snb View Post
    I hope you did realise that the result will be saved in the document 'form 001.doc'

    In the attachment a workbook in which you won't need to change anything, provided you store this workbook in the same folder as that containing the worddocument.
    You only have to run the macro:
    I tried this and it created a document called 'form 001.doc' but when I opened it none of the values were transposed.

    Am I doing something wrong?

    I selected the row I want and highlighted column A to K, then press Alt+F8, and then run the macro.

  12. #12
    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.

    Quote Originally Posted by Wendy_The_Intern_<3 View Post
    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.
    ?
    The code is not working as you use doc template not attached but yours. The attached file has fields set to accept Excel data in appropriate positions.

  13. #13
    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.

    @wendy

    It's not necessary to select a row. You can select any cell (only 1) in a row and run the macro.

  14. #14
    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.

    How do you set fields to accept Excel data?

    I appreciate the help everyone!

  15. #15
    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

    In the Word document Menubar/insert/fields/select docvariable/enter a variable name

    Alternative method:

    ctrl-F9; now two accolades { } appear.
    Type between the accolades DOCVARIABLE name
    the result : {DOCVARIABLE name}

    'name' is the name of the variable; you can chose any name, as long as you don't use spaces; if you do you need to hyphenate the name like:t "new name"
    You can only attribute a value to a docvariable using VBA.
    You can toggle the 'visibility' of this field using te toggle button Alt-F9.

+ 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