+ Reply to Thread
Results 1 to 9 of 9

Copying Rows Based on Cell Value

  1. #1
    Forum Contributor
    Join Date
    05-01-2018
    Location
    Maine
    MS-Off Ver
    2010
    Posts
    114

    Copying Rows Based on Cell Value

    Hello,

    I have a VBA code that seems to almost work but I am having an issue with 2 parts of it I would appreciate some help with.

    I have 2 sheets, 'Totals' and 'Data'. 'Totals' is essentially the consolidated version of the 'Data' sheet. The 'Data' sheet has a list of employees in column A with other info filling out to the columns to the right. I am needing a VBA code that will copy that info over to 'Totals' based on cell G4 in 'Totals'. If the word in G4 matches text in column A in the 'Data' sheet then copy the row to the first blank cell starting at C14 on the 'Totals' sheet.

    Here is what I am looking to do:

    1. If text in G4 says Joe Schmo on the 'Totals' sheet then search the 'Data' sheet column A for a match. G4 will most likely be a drop down menu with the names.
    2. If match is found then copy text (only) from row and paste to 'Totals' starting at C14 on first blank row (there may be 10-20 rows that are copied at a time)

    Here is the code I have been working with. After some changes I now have errors:

    Please Login or Register  to view this content.
    As you can see, I am having an issue figuring out how to change "If c = "Joe Schmo" Then" to say "If C = Target.G4 Then" or something like that. Meaning that instead of specific text in the VBA code it actually reads the text in G4 on 'Totals'. I also am having an issue specifying that the cell it should paste on starts at C14 instead of A1 on "Totals". Lastly, I cant seem to remember how to say that I want text only as opposed it to keeping the formatting from the 'Data' sheet.

    Just to make it as easy as possible I included a test workbook.

    Thank you in advance for any assistance.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Copying Rows Based on Cell Value

    This uses Autofilter in the Data sheet. It assumes the top row is a header.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Copying Rows Based on Cell Value

    Place this in Sheets("Totals") sheet Module...
    Code runs on selection in G4

    I am assuming that all other should be cleared...

    Please Login or Register  to view this content.
    Place this in std module to populate dropdown with unique list
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sintek; 03-11-2021 at 02:17 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Forum Contributor
    Join Date
    05-01-2018
    Location
    Maine
    MS-Off Ver
    2010
    Posts
    114

    Re: Copying Rows Based on Cell Value

    Thank you both for the code, I really appreciate it. I actually could not get Alphafrogs to load into the Data sheet. It seems to create a filter but not actually move data over to Totals?

    Sinteks is working but I have one question. The code moves the data over based off the drop down (which is great, I didnt even think to use it in that manner) but it doesnt respond well if the person on the 'Data' sheet only has 1 row of data. It returns the error 'subscript out of range' and then will not work again. Any idea how to correct that? It should still return if there is only 1 row of data which I didnt think about initially. It errors out on this line in the Private Sub "Range("C14").Resize(UBound(Arr, 1), UBound(Arr, 2)) = Arr"

    Thank you both for the assistance. I really really appreciate it.
    Last edited by Darkcloud617; 03-11-2021 at 09:58 AM.

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Copying Rows Based on Cell Value

    Please Login or Register  to view this content.
    Last edited by sintek; 03-11-2021 at 10:10 AM.

  6. #6
    Forum Contributor
    Join Date
    05-01-2018
    Location
    Maine
    MS-Off Ver
    2010
    Posts
    114

    Re: Copying Rows Based on Cell Value

    This works absolutely perfectly and will save us tons of time. Thank you so much. I really appreciate your help.

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Copying Rows Based on Cell Value

    .........................
    Thanks.png

  8. #8
    Forum Contributor
    Join Date
    05-01-2018
    Location
    Maine
    MS-Off Ver
    2010
    Posts
    114

    Re: Copying Rows Based on Cell Value

    Hello, this is the first time we will be using this report for the month and it is getting an error message:

    "Removed Feature: Data validation from /xl/worksheets/sheet1.xml part"

    any ideas on what could be causing that? The data does not seem to be transferring over?

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: Copying Rows Based on Cell Value

    You might want to remove the solved tag if you require further assistance.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. Copying rows to another location based on another cell.
    By nobelborn in forum Excel General
    Replies: 2
    Last Post: 01-05-2020, 07:11 PM
  2. Copying rows from worksheet to another based on cell value
    By prempre in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-18-2015, 01:24 PM
  3. Copying rows to different sheets based upon cell value
    By 65kingsland in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-07-2015, 01:27 PM
  4. [SOLVED] Copying partial rows based on contents of one cell.
    By TomRet in forum Excel Programming / VBA / Macros
    Replies: 42
    Last Post: 01-02-2014, 02:48 PM
  5. Copying Rows Based on Specific Cell Match
    By ywendyh in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2013, 07:35 PM
  6. Need Help Copying and Linking Rows Based on Cell Value
    By RB737 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-17-2013, 02:46 PM
  7. Replies: 0
    Last Post: 08-31-2010, 04:03 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