+ Reply to Thread
Results 1 to 6 of 6

copy rows based on 1 criteria + user input + pastevalues (almost there...)

  1. #1
    Registered User
    Join Date
    05-12-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    14

    Question copy rows based on 1 criteria + user input + pastevalues (almost there...)

    I guys, I'm not a programer so I'm having an hard time with this one... I have this macro already working but I just can't use PasteSpecial (as values) and don't understand why.... (I think I has to do with ranges proprieties but I'm a little lost...)

    Please Login or Register  to view this content.
    This already does the job, It copies the data if K="END" and if B have the date inserted by the user (the date is in dd/mm/yyyy hh:mm format so I used a string). The problem is that it copies the formulas (and it was a lotttt of them...), and I need just the values but I simply can't get the .PasteSpecial to work... could anyone help me with this one? or just point me in the right direction?

    Many thanks in advance,

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: copy rows based on 1 criteria + user input + pastevalues (almost there...)

    This will not only demonstrate how to do a PasteSpecial into the next empty row on Sheet2, it will show you how to use the autofilter to apply your criteria to the entire dataset at once and copy all matching rows at one time, you don't have to loop through one row at a time testing.

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    05-12-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: copy rows based on 1 criteria + user input + pastevalues (almost there...)

    Many thanks for the quick reply JBeaucaire, unfortunately it doesn't work...it always says that there where no matches.

    I tried to delete the inputbox criteria to see if I could understand the error and it started to work but only copying the cells in column A. I changed a little more the code and it started to copy almost all cells, the problem is that it can't paste empty cells.

    Please Login or Register  to view this content.
    Also this is without the string verification. I will try to understand all the code that you used to see if I find a solution.

    EDIT: I edited the line:
    .Range("A3:AB" & LR).Copy -> Since AB is the last column with data.

    EDIT2:tried to add an attachment but no joy... (xlsm < 30kb)
    Last edited by Dieneces; 07-22-2013 at 11:13 AM. Reason: attachment

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: copy rows based on 1 criteria + user input + pastevalues (almost there...)

    I'll be happy to test this on a sample workbook if you'd care to upload one with the names desensitized.

  5. #5
    Registered User
    Join Date
    05-12-2011
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: copy rows based on 1 criteria + user input + pastevalues (almost there...)

    Finally I was able to upload the file... had to use the basic uploader.

    Now, in the example file if we run the macro and type 24/06/2013 it was suppose to copy rows 2 and 6 to sheet2 (the ones that have END in column K and 24/06/2013 in column B.

    With the script that I posted it does that but I can't use pastevalues (I believe it is because I'm not using range...)

    Many thanks for your expert advise,
    Attached Files Attached Files

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: copy rows based on 1 criteria + user input + pastevalues (almost there...)

    Yeah, I see a few things.

    1) Be sure to read through the code carefully until it's clear what each line of code is doing.

    2) The macro isn't copying headers, so copy your row1 headers onto Sheet2 so they're there permanently.

    3) After you've done that, one assumes you want sheet2 "reset" each time you use it, so I added a line of code to clear rows2 downward.

    4) Your data starts on row2 of the example sheet, but your macro in Post#1 implied the data started in row3. I've edited the macro to apply the Autofilter into the headers in row1 instead of row2. Autofilter has to be in the row directly above the data.

    5) I've changed your LSearchValue variable so that is specifically a Date value in the declarations. Then we're going to use a range filter again to show any date value on that day.

    Please Login or Register  to view this content.

+ 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]Hide Rows and Columns Based on User Input
    By thesteve in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2013, 01:32 PM
  2. Macro to Copy Rows based on User Input
    By CharterJP in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-24-2012, 06:13 PM
  3. Automate formulated rows based on user input
    By G2S in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-01-2012, 10:06 PM
  4. macro to copy cells based on user input
    By pankaj2145 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-03-2009, 04:54 AM
  5. Delete rows based on user input
    By Militia in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-10-2009, 06:33 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