+ Reply to Thread
Results 1 to 13 of 13

VBA help for a complete beginner - Copy and pasting from Excel to Word template

  1. #1
    Registered User
    Join Date
    08-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    VBA help for a complete beginner - Copy and pasting from Excel to Word template

    Hello Everyone

    I am a complete novice at VBA having only picked it up a day or two ago with no previous programming experience. Here's my problem if anyone out here is able to help:

    I have created an excel document that can be used to populate a table on one of the worksheets (Switching Sequence) using a number of different drop down boxes. The choices made on the drop down boxes are shown in another table on another worksheet (Populated Table). This table on "Populated Table" needs to be copied and pasted into an existing template where it can be saved and printed off for use.

    The table consists of the following rows:

    Operation Number (column B) , Location (column C), Circuit or Device (column D), Operation (column E), Complete? (column F), Date and Time (column G)

    Is there a way in which my code is able to copy the table (range B5:G82) and then only past the rows in which there is an Operation in its corresponding D cell?

    Here is what I have already. So far it copies and pastes the whole range (B5:G82) but I am unable to make it ignore the rows with a blank in it's corresponding D column.

    Please Login or Register  to view this content.
    I will attach my excel sheet so if anyone has chance they can have a proper look at it.

    So in summary I want to be able to:

    1. Populate table in Excel
    2. Copy table
    3. Paste table in word template but without the rows with a blank cell in its D column


    Any help would be amazing

    Many thanks

    AM2809
    Attached Files Attached Files
    Last edited by am2809; 08-16-2017 at 04:09 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: VBA help for a complete beginner - Copy and pasting from Excel to Word template

    So you want to copy each row where the "D" cell is not blank? Also, please put your code in
    Please Login or Register  to view this content.
    tags or a moderator will not let people reply to your post.

  3. #3
    Registered User
    Join Date
    08-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: VBA help for a complete beginner - Copy and pasting from Excel to Word template

    Hi

    Really sorry, I'm new to this and this website. Put my code in tags?

    Basically I am wanting to copy the table from the "Populated Table" sheet onto a blank word template. If the table in "Populated Table" has blank rows in it i.e. there are no Operations (Column E - My Mistake) then I want it to be able to automatically omit these rows from the copy paste to the word template.

    For example. A switching schedule might have 10 operations in it (rows 1 to 10) but anything after that (rows 11 onwards) will be blank. So I wondering if it doable to be able to omit these automatically without having to change the copy paste range everytime to only include the rows with Operations in it?

    Thanks for your help

    AM2809

  4. #4
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: VBA help for a complete beginner - Copy and pasting from Excel to Word template

    If you go to edit your original post, select your code and hit the "#" symbol (not # on your keyboard, it will be next to Bold, Italic, Underline etc.)

    Will you ever have a blank row separated by two non-blank rows? E.g. row 8 has no operation, but rows 7 and 9 do?

  5. #5
    Registered User
    Join Date
    08-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: VBA help for a complete beginner - Copy and pasting from Excel to Word template

    Awesome, that looks better.

    No. There will be no blank row separated by two non blank rows.

    Many thanks

    AM2809

  6. #6
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: VBA help for a complete beginner - Copy and pasting from Excel to Word template

    Ok you can give this a try
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: VBA help for a complete beginner - Copy and pasting from Excel to Word template

    Hi

    I copy and pasted it into the compiler and it worked great. But then I added another few Operations to the "Populated Table" and now it doesn't seem to be working. In the example attached there are only 9 operations but in reality there could be over 50. This is why I have included a big range for the copy paste (B5:G82).

    Many thanks

    Andrew

  8. #8
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: VBA help for a complete beginner - Copy and pasting from Excel to Word template

    Sorry the formulas pasting blank values is messing with it (didn't realize it was acutally being interpreted as the cells containing 0 rather than nothing). Try changing
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: VBA help for a complete beginner - Copy and pasting from Excel to Word template

    I believe have figured out the problem why it stopped working.

    Within the 'blank' Operation cells there is actually the =formula to link it to the output of the table on the "Switching Sequence" workbook. Will this mean that it is being read as a non-blank cell? Are there ways to make ignore the linking formula in the 'blank cells'

    Many thanks

    am2809

  10. #10
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: VBA help for a complete beginner - Copy and pasting from Excel to Word template

    See post above (I figured out the issue around the same time you did). The new edit will work as long as your "operations" are never one character long

  11. #11
    Registered User
    Join Date
    08-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: VBA help for a complete beginner - Copy and pasting from Excel to Word template

    Amazing! You've done it. I am so grateful.

    If I am ever in Toronto I'll by you a beer.

    If I could be cheeky and ask one more question?

    Is there a way in VBA to give the pasted table a top border after it has been pasted and the table splits over two pages? At the moment when a table is too big for one page then the border at the top row on the second page doesn't have a top border.

    Kind regards

    AM2809

  12. #12
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: VBA help for a complete beginner - Copy and pasting from Excel to Word template

    I appreciate it!

    Sorry I'm really not sure how to do that - I don't use vba outside of excel and outlook, so I'm not sure how to deal with borders in word. If you start a new thread someone should be able to help you (they normally don't want you asking multiple questions in one thread)

  13. #13
    Registered User
    Join Date
    08-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: VBA help for a complete beginner - Copy and pasting from Excel to Word template

    Ok I will do that.

    Thanks again!

    AM2809

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to copy word to excel for beginner
    By maiser in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-28-2017, 04:08 AM
  2. VBA Excel to Word copy and pasting
    By JimmyWilliams in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-25-2017, 06:45 PM
  3. [SOLVED] Copy contacts from Excel to a Word label template
    By Casperinoz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-23-2013, 12:30 AM
  4. Importing multiple text files into Excel, for a complete beginner
    By halldin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2013, 07:52 AM
  5. [SOLVED] Pasting Excel Values To Word Template - PROBLEM, NEED SOLVED URGENT
    By TheProffesional in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-14-2012, 10:25 PM
  6. excel copy cells to word template
    By Garr in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 08-07-2006, 11:35 PM
  7. [SOLVED] excel copy cells to word template
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-05-2006, 05:00 AM

Tags for this Thread

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