+ Reply to Thread
Results 1 to 14 of 14

VBA to Paste cells acording to list of cell references

  1. #1
    Registered User
    Join Date
    07-01-2011
    Location
    Australia
    MS-Off Ver
    Excel 2011 (Mac)
    Posts
    38

    VBA to Paste cells acording to list of cell references

    Hi Guys - Hope you are well.

    I have some VBA that I would like some help to write - I'm not really sure where to start.

    I would like to paste cells from a contiguous range to a non-contiguous range using a list of cell references as the target paste cells. Both the target and the source cells will be on the same sheet. The source cells will contain an INDEX/MATCH formula - the result in each cell is what I wish to copy then paste. I would like to activate the code by assigning the macro to a button.

    The source columns look roughly like this:

    Title Index/match result Cell reference to paste to
    Text 1 23 B5
    Text 2 Peter H7
    Text 3 Continuous D11
    Text 4 [BLANK] F7
    Text 5 Membrane J12
    ....... ....... .......
    Text 57 Yes K33

    The Target columns are all over, as shown by column three above. I would like the code to run though the full list of index match results all the way to the last 'Text 57' - the code can either skip blanks or paste these also, I don't mind. I haven't written the INDEX/MATCH yet so it may return zeros if there is no data to pull.

    I attach the full example here.
    Entry Form EG.xlsx
    I really appreciate your help.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,893

    Re: VBA to Paste cells acording to list of cell references

    While this can all be accomplished with VBA, wouldn't it be just as easy to put in each of the destination cells =SourceAddress, where SourceAddress is the cell reference. Save the spreadsheet as a template and each time it is opened and populated, it is saved as a worksheet. Seems a bit easier than writing 57 lines of copy and 57 lines of pastespecial codes.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    07-01-2011
    Location
    Australia
    MS-Off Ver
    Excel 2011 (Mac)
    Posts
    38

    Re: VBA to Paste cells acording to list of cell references

    Hi Alan,

    Thanks for your reply.

    Yes normally this is what i would do, however I use the worksheet as a form that users can enter data into. What I am trying to achieve is to be able to to populate the form with the info existing in the database so they can see what is there and either overwrite it or leave it if they think it is more current than what they have. Once they have edited all or some of the cells I have a button they can click to copy the combined or new data back to the database.

    I thought I might be able to save 57 lines of code by having the cell reference in a list that VBA could use rather than having to put in the actual cell reference in the code.

    Do you think this is possible?

    Thanks again.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,893

    Re: VBA to Paste cells acording to list of cell references

    I don't have a simpler answer, but have requested help from others in the forum.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: VBA to Paste cells acording to list of cell references

    In its simplest form, you could use something like:

    Please Login or Register  to view this content.

    Regards, TMS
    Attached Files Attached Files
    Last edited by TMS; 06-03-2014 at 11:24 AM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: VBA to Paste cells acording to list of cell references

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    Please Login or Register  to view this content.
    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  7. #7
    Registered User
    Join Date
    07-01-2011
    Location
    Australia
    MS-Off Ver
    Excel 2011 (Mac)
    Posts
    38

    Re: VBA to Paste cells acording to list of cell references

    Thanks Alan for putting the call out - much appreciated.

  8. #8
    Registered User
    Join Date
    07-01-2011
    Location
    Australia
    MS-Off Ver
    Excel 2011 (Mac)
    Posts
    38

    Re: VBA to Paste cells acording to list of cell references

    Thanks so much TMS - just off to the land of nod - I will run the code in the morning.

  9. #9
    Registered User
    Join Date
    07-01-2011
    Location
    Australia
    MS-Off Ver
    Excel 2011 (Mac)
    Posts
    38

    Re: VBA to Paste cells acording to list of cell references

    Thanks for your help Sixth Sense - I will test it tomorrow. Just off to bed!

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: VBA to Paste cells acording to list of cell references

    just off to the land of nod
    No staying power

    Regards, TMS

  11. #11
    Registered User
    Join Date
    07-01-2011
    Location
    Australia
    MS-Off Ver
    Excel 2011 (Mac)
    Posts
    38

    Re: VBA to Paste cells acording to list of cell references

    Hi Trevor,

    Thanks for your continued help.

    I was quite amazed at how little code there was - "All hail Trevor"

    There is one small hiccup that hopefully shouldn't be too difficult to fix. The code currently copies the formula in the index/match column and the formatting - is it possible to just have the values pasted over such as happens when one does the "past special>paste values"?

    Thanks again for your help.

    Zac

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: VBA to Paste cells acording to list of cell references

    You're welcome. Thanks for the rep

    Untested:

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    07-01-2011
    Location
    Australia
    MS-Off Ver
    Excel 2011 (Mac)
    Posts
    38

    Re: VBA to Paste cells acording to list of cell references

    Hi Trevor - that fixed it!

    Thanks for your generous help.

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: VBA to Paste cells acording to list of cell references

    You're welcome. Thanks for the rep. . Again

+ 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. Replies: 5
    Last Post: 10-26-2013, 02:51 PM
  2. Sorting list acording to lookup values
    By ABSTRAKTUS in forum Excel General
    Replies: 3
    Last Post: 06-14-2011, 04:19 PM
  3. New Sheet acording to Cell name/value VBA
    By phoztek in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 10-20-2009, 06:43 AM
  4. Cut and Paste cells without moving cell references
    By mikeyfear in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-02-2008, 06:31 AM
  5. filling cells acording to the first 3 numbers
    By pmarques in forum Excel General
    Replies: 1
    Last Post: 09-09-2005, 07:31 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