+ Reply to Thread
Results 1 to 20 of 20

Copy and Paste in different locations depending on adjacent cell value

  1. #1
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Copy and Paste in different locations depending on adjacent cell value

    I have the below which is meant to look for the first instance of "Test" in column B and once found copies the cells directly to the left of it and pastes it onto Sheet3 Cell AJ3 if the value of the cell 2 cells to the right of where 'Test' is found matches cell C1 but it should paste it to SHeet3 AK3 if the cell 2 cells to the right of where 'Test' is found matches cell D1. The code runs but does nothing. I'm really close I think so it must just need some minor tweaks?

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Copy and Paste in different locations depending on adjacent cell value

    This line looks unusual :
    Please Login or Register  to view this content.
    as does
    Please Login or Register  to view this content.
    Your Excel must be different to mine if you have a row 0
    Which row are you trying to select?

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy and Paste in different locations depending on adjacent cell value

    Maybe:

    Please Login or Register  to view this content.
    Last edited by xladept; 01-18-2016 at 12:39 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Copy and Paste in different locations depending on adjacent cell value

    Quote Originally Posted by Kevin# View Post
    This line looks unusual :
    Please Login or Register  to view this content.
    as does
    Please Login or Register  to view this content.
    Your Excel must be different to mine if you have a row 0
    Which row are you trying to select?
    So if it finds "Test" in say cell B90 then rng(0, 2) would be cell D90. Is that right?

  5. #5
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Copy and Paste in different locations depending on adjacent cell value

    Quote Originally Posted by xladept View Post
    Maybe:

    Please Login or Register  to view this content.
    That runs without error much like my previous code, but it does nothing. It's like it doesn't meet the criteria to paste, but it definitely does. Is it something to do with the cell references and offsets I'm thinking?

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy and Paste in different locations depending on adjacent cell value

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  7. #7
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Copy and Paste in different locations depending on adjacent cell value

    Sample.xlsm

    Attached Sample file

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy and Paste in different locations depending on adjacent cell value

    Hey Dog,

    There is no "Test" in column B

  9. #9
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Copy and Paste in different locations depending on adjacent cell value

    Sample.xlsm

    Silly me, attached the wrong one. Correct on here.

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy and Paste in different locations depending on adjacent cell value

    I put "Test" in B32 and ran this:

    Please Login or Register  to view this content.

  11. #11
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Copy and Paste in different locations depending on adjacent cell value

    Quote Originally Posted by xladept View Post
    I put "Test" in B32 and ran this:

    Please Login or Register  to view this content.
    It runs without error, but it doesn't paste anything....it should match what is in 'Sheet 3 After' in the sample sheet.

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy and Paste in different locations depending on adjacent cell value

    it works for me - try it again - with "Test" B32 - that's exact

  13. #13
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Copy and Paste in different locations depending on adjacent cell value

    I see what has happened. OK, the latest attached sheet and the Sheet3 After is what I want after the macro runs. You'll see that it'll need some sort of loop I'm guessing?

    Sample.xlsm

  14. #14
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy and Paste in different locations depending on adjacent cell value

    Hi ScabbyDo,

    Just comment out the Exit For

    Please Login or Register  to view this content.
    And - Thanks for the rep!
    Last edited by xladept; 01-18-2016 at 05:34 PM.

  15. #15
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Copy and Paste in different locations depending on adjacent cell value

    Think we're close now.

    Final alteration made to the sample sheet now if you could review. Once this is done I'll give you even more rep!

    Final-Sample.xlsm

  16. #16
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy and Paste in different locations depending on adjacent cell value

    Hi ScabbyDog,

    Try this:

    Please Login or Register  to view this content.

  17. #17
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Copy and Paste in different locations depending on adjacent cell value

    Quote Originally Posted by xladept View Post
    Hi ScabbyDog,

    Try this:

    Please Login or Register  to view this content.

    The recent code you posted works perfectly on my sample sheet provided but not when I transfer the code to the sheet I am working on. I've attached the exact data I'll be generally using to see if you can get it to work with it! No idea why it wouldn't be working as the cell references are still correct. I'm guessing it's something to do with finding the last used row in column B?

    Final-Sample.xlsm

  18. #18
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy and Paste in different locations depending on adjacent cell value

    Hi Scabby,

    In the other samples you actually had "WordA and WordB" - but not with this one - try this:

    Please Login or Register  to view this content.

  19. #19
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Copy and Paste in different locations depending on adjacent cell value

    Thanks so much! Really appreciate your help with this. Solved!

  20. #20
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy and Paste in different locations depending on adjacent cell value

    You're welcome and thanks for the rep!

+ 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: 1
    Last Post: 01-03-2014, 03:01 AM
  2. [SOLVED] VBA for searching string in a column and copy rows depending on string in adjacent cell
    By xprakash in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-20-2013, 05:58 AM
  3. [SOLVED] VBA to copy & Paste Adjacent cell when value found
    By shiva_reshs in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 09-12-2013, 10:47 AM
  4. [SOLVED] find value, copy value of adjacent cell and paste it on another sheet
    By Ajgor in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-25-2012, 04:21 PM
  5. Copy and Paste macro depending on a cell
    By john_london in forum Excel General
    Replies: 4
    Last Post: 11-08-2010, 11:05 AM
  6. Copy and Paste Depending on Cell
    By Craig2097 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2010, 11:29 AM
  7. Copy & Paste values in adjacent cell
    By excelkeechak in forum Excel General
    Replies: 11
    Last Post: 12-05-2009, 07:11 PM

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