+ Reply to Thread
Results 1 to 3 of 3

Code to copy selection of rows from master into template file

  1. #1
    Registered User
    Join Date
    10-18-2017
    Location
    London, England
    MS-Off Ver
    2013 at work, 2016 at home
    Posts
    1

    Code to copy selection of rows from master into template file

    Hi all,

    My first post so apologies in advance if I am not following any of the correct protocol in anyways.

    I am working off a master sheet and coping a selection of rows based on filter into a template file.

    Considering I am quite inexperienced with macros, I have managed to do fairly well using the Record button in EXcel. The code can do with some tidying up.

    Master Spreadsheet contains

    COL A Batch No
    COL B Unique ID
    COL C Account
    COL D System
    (There are a few columns in between but I do not need these for copying into template.)
    COL L Type
    COL M Location
    COL N AccountDescription
    COL O Owner Email

    The template that I am copying to contains
    Sheet 1 - General Information, How to complete the form in Sheet 2
    Sheet contains:
    COL A Unique ID
    COL B Account
    COL C System
    COL D,E,F,G,H are a mixture of free text and drop downs that the user will have to fill in and are shaded yellow.
    COL J Type
    COL K Location
    COL L Account Description.

    Hope that helps you understand sheets I am working with.
    • On the master I manually filter by OwnerEmail and assign a Batch No that helps me identify them. 1 owner could have anything from 1- 280 accounts.
      Once filtered, I would copy / paste Col B,C,D from Master, Paste into Col ABC of Template
      copy/past Col LMN into JKL.
      Col A is copied into sheet as white text - this used for the naming of the file.

    I have managed to get all that working with the Record, however as the number of rows copies varies from owner to owner, I have to manually tidy up COL D,E,F,G,H on template.

    Ideally i would like your assistance to achieve 2 things - put in a macro code of some sorts that will recognise empty rows and delete, and where there is surrounding data in ABC, and JKL of template it will format the sheet with drop downs as above. This I think is probably quite easy to achieve, I just dont know how which is why i am here.
    Secondly if there is way to tell the macro, for each batch id - run this macro. that will be amazing!

    Also sorry I have been unable to post up real data as I am working with confidential data at work.

    Thanks in advance

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: Code to copy selection of rows from master into template file

    Can you post a sample workbook?

  3. #3
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Code to copy selection of rows from master into template file

    Copy and paste is not a very efficient way to move data like this. It will do in a pinch but its slow and can be buggy, especially as the amount of data increases.

    A step up from this would be to use something like a For loop to loop the cells (range objects) in a given column/row and set the destination range.value property to the value from the source range.value. This is still slow but should work faster and be easier to modify than recorded copy/paste or even using copy/paste methods.

    From what I can gather from your post, your source and destination are also not apples to apples in terms of layout. There are columns you mention in one but not the other. This makes it harder to move content in bulk instead of 1 cell at a time.

    If your source and destination where identical column layouts you could simply store the source range in an array and then dump that array into a source range on the destination sheet. This is by far the quickest method to move data, but only works when the source and destination are the same dimensions.

    Its hard to provide specific advice without a sample. From the sounds of it your not a programmer. So its likely any generic input wont help you much.

+ 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. Creating a code to count and extract data from template to master file
    By B_Jarbs in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-07-2016, 11:32 AM
  2. Master sheet into template, copy template to sheets named after master column.
    By M4R1N3R in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2015, 12:24 PM
  3. [SOLVED] exporting data from master file to template file (autopopulate a template)
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-06-2014, 11:41 AM
  4. Replies: 2
    Last Post: 02-08-2014, 04:45 AM
  5. Loop to copy the same rows from multiple files to a master file
    By allen123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-29-2012, 09:15 PM
  6. VBA code to allow users to work on the copy of master file.
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-19-2010, 10:41 AM
  7. copy rows from sheet using a template to a word file
    By lightningt12312 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 04-09-2009, 06:21 AM

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