+ Reply to Thread
Results 1 to 8 of 8

VBA Copy/paste data based on cell reference (indirect)

  1. #1
    Registered User
    Join Date
    01-20-2015
    Location
    abc
    MS-Off Ver
    Excel 2017
    Posts
    10

    VBA Copy/paste data based on cell reference (indirect)

    Hi,

    I think I have a very simple question, but after a lot of searching I have not been able to come up with a solution..

    The problem I try to solve with a macro:
    I have one cell that based on a lookup will return a certain column letter. If the cell return F, I want to copy data in F3:F7 in sheet 1, and if it returns G I want to copy data in G3:G7. The only thing that is dynamic is the column reference. So I need is to be able to insert the lookup value to the copy selection inside the macro.

    Any help would be highly appreciated!

    Thank you!
    Last edited by dunder; 02-18-2019 at 11:28 AM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,775

    Re: VBA Copy/paste data based on cell reference (indirect)

    Which cell has the lookup formula and where do you want to paste the copied range?
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA Copy/paste data based on cell reference (indirect)

    let's say the cell that returns the column letter is A2.

    Please Login or Register  to view this content.
    This uses the col varible to capture the value in the cell that returns the column letter. It then uses that variable to construct the range to be copied.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  4. #4
    Registered User
    Join Date
    01-20-2015
    Location
    abc
    MS-Off Ver
    Excel 2017
    Posts
    10

    Re: VBA Copy/paste data based on cell reference (indirect)

    Thank you! I will try this.

  5. #5
    Registered User
    Join Date
    01-20-2015
    Location
    abc
    MS-Off Ver
    Excel 2017
    Posts
    10

    Re: VBA Copy/paste data based on cell reference (indirect)

    I am getting an error, but I think it is due to the copy is to be performed in another sheet?

    A bit more description:
    My lookup value (F) is in Sheet1, f.ex "A2", and I want to copy (F)3: (F)7 in Sheet2, then paste F3:F7 in the same cells (basically I am making a macro to clear formulas based on if a date has passed).

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,775

    Re: VBA Copy/paste data based on cell reference (indirect)

    Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet.

    Please Login or Register  to view this content.
    Since you didn't indicate where on Sheet2 you wanted to paste the data, this macro will paste to the first available row in column A.

  7. #7
    Registered User
    Join Date
    01-20-2015
    Location
    abc
    MS-Off Ver
    Excel 2017
    Posts
    10

    Re: VBA Copy/paste data based on cell reference (indirect)

    Thank you! Worked perfectly!

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,775

    Re: VBA Copy/paste data based on cell reference (indirect)

    You are very welcome.

+ 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. [SOLVED] Copy & paste - based on reference
    By Median in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-03-2018, 02:53 AM
  2. Copy based on Relative Cell Reference and paste to Fixed cells
    By CDNcameron in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-26-2014, 04:40 PM
  3. Copy and Paste Data based on a value within a cell
    By gally in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2013, 04:43 AM
  4. [SOLVED] Copy inconsistent data based on recurring cell reference & sequentially paste in new wksht
    By Tbenefits in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-28-2013, 10:46 AM
  5. [SOLVED] How to reference an entire row based on an indirect cell reference
    By echo_oscar in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-31-2012, 08:50 PM
  6. Copy & paste specific column based on cell reference
    By ccsmith in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2011, 03:59 AM
  7. Copy and Paste macro needs to paste to a changing cell reference
    By loulou in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2005, 07:06 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