+ Reply to Thread
Results 1 to 28 of 28

try to Copy entire Row if active cell equals variable

  1. #1
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    try to Copy entire Row if active cell equals variable

    Hey all,

    I've been working on this for about a week and am having some troubles with the final steps. This is my very first attempt at VBA with ZERO experience with it, so please be kind if this is an extremely Noobie question.

    I cannot for the life of me get the macro to copy the entire row. I know it has to be a something I'm doing wrong in the code. The closest I have come is getting the macro to copy a single cell. Below is the macro code as it sits right now. Any help would be very much appreciated.

    Please Login or Register  to view this content.
    Last edited by Mfederman; 04-26-2017 at 02:35 PM. Reason: seperated Code out for easier reading.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    Hi Mfederman

    Welcome to the Forum.
    In future please view the forum rules before posting. Your post does not comply with rule #3.
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the [#] button at the top of the post window.
    Would be ideal to see a sample workbook. Start with changing this line of code
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    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 [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    My apologies. I have fixed the Code issue and have added an attachment that is a sample from the workbook I'm working with.

    Thank you very much for the suggestion Sintek! any other advice you can offer?

    I'm also trying to get the Macro to save the newly created workbook based on the variable Payrolldate, is that possible?

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    Please rather add a sample file...not a image. Cannot do tests on a image.
    Originally Posted by Pete_UK
    To do this, click on Go Advanced (below the Edit Window) while you are composing a reply, then scroll down to and click on Manage Attachments and the Upload window will open. Click on Browse and navigate to (and double-click) the file icon that you want to attach, then click on Upload and then on Close this Window to return to the Edit window. When you have finished composing your post, click on Submit Post.

  5. #5
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    VBA didn't like the Range.offset, so I changed it back to Activecell.offset and that got rid of my error there. Now I'm getting another error that is as follows.

    "Run-time error '91':
    Object Variable or with blocl variable not set"

    When I hit the Debug button, it highlights the like where I display the input box to set the variable.

  6. #6
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    ok, Sorry about that. I have uploaded a portion of the actual worksbook.
    Attached Files Attached Files

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Please rather add a sample file...not a image. Cannot do tests on a image.

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    Are you wanting to copy all the rows that match the payroll input date to a new workbook.
    Your variable
    Please Login or Register  to view this content.
    is giving the error

  9. #9
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    Yes I do. The end goal is to create a CSV file of the current payroll date (payrolldate variable) to be uploaded to our payroll company's website.

  10. #10
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    What should the payrolldate variable be then? Would it not be a range?

  11. #11
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    Try this: Not happy with the loop. Perhaps someone can add code with a Do While syntax
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Sintek; 04-25-2017 at 02:29 PM. Reason: Had to declare a variable

  12. #12
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    You are awesome. I REALLY appreciate you taking the time to put this together!
    I just copied and pasted the code in to a new module and tried to step through and got a new error:

    "Run-time error '6': Overflow"

    I'm not sure what that means.

    The line that gets highlighted when I hit debug is
    Please Login or Register  to view this content.
    "

  13. #13
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    Go with this code...Do while loop
    Please Login or Register  to view this content.
    Last edited by Sintek; 04-25-2017 at 03:03 PM. Reason: Added a errorhandler

  14. #14
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    Quote Originally Posted by Mfederman View Post
    You are awesome. I REALLY appreciate you taking the time to put this together!
    I just copied and pasted the code in to a new module and tried to step through and got a new error:

    "Run-time error '6': Overflow"

    I'm not sure what that means.

    The line that gets highlighted when I hit debug is
    Please Login or Register  to view this content.
    "
    Yep, sorry...Need to declare i As a Double and not Integer
    So
    Please Login or Register  to view this content.
    must be
    Please Login or Register  to view this content.

    EDIT: But seriously go with my second code...Post # 13 Works much better.
    Last edited by Sintek; 04-25-2017 at 02:52 PM.

  15. #15
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    This one does not find anything after I enter the date in the input box.

    Quote Originally Posted by sintek View Post
    Go with this code...Do while loop
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    This one now works great, but also does not return any results when I enter the payroll date I'm looking for.

    Again, I can't thank you enough for your help on this!

    Quote Originally Posted by sintek View Post
    Yep, sorry...Need to declare i As a Double and not Integer
    So
    Please Login or Register  to view this content.
    must be
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    Thank you for adding in the errorhandler. However, it's still not coming back with any results that it's copying and pasting into the new workbook. I know without a doubt that I am entering a valid string as a date.

    Quote Originally Posted by sintek View Post
    Go with this code...Do while loop
    Please Login or Register  to view this content.

  18. #18
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    Oops sorry....My destination folderpath is in code
    Herewith amended....See both files and amended code in Post13
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    I'm not sure why, but I still keep getting the msgbox that shows "No payroll records with that state date exists"

    It's still not "finding" anything in my original file. The original file has over 39,000 rows in it currently and will continue to grow with each week that passes. I'm not sure if that matters or not.

    Quote Originally Posted by sintek View Post
    Oops sorry....My destination folderpath is in code
    Herewith amended....See both files and amended code in Post13

  20. #20
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    Have you tested my attached and seen it works.

    Search for a date that is in the first couple of rows and Dim i As Long
    Last edited by Sintek; 04-25-2017 at 03:30 PM.

  21. #21
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    I did try. It doesn't work for me. Is it possibly something to do with our different versions of excel? I see you're in 2007 and I'm using 2010.

    Quote Originally Posted by sintek View Post
    Have you tested my attached and seen it works.

  22. #22
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    Search for a date that is in the first couple of rows and
    Please Login or Register  to view this content.

  23. #23
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    Is it possibly something to do with our different versions of excel? I see you're in 2007 and I'm using 2010.
    Don't think so...

  24. #24
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    I made that change and tried to find the very first payroll date in coloum F. It was able to find that without a problem. But it won't find anything after that first payroll date

  25. #25
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    And your dates are in that format YYYYMMDD
    EDIT:
    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Last edited by Sintek; 04-25-2017 at 03:45 PM.

  26. #26
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    yep. Definitely. They have to be since that's how it comes from the database that's linked to sheet 1

  27. #27
    Registered User
    Join Date
    04-25-2017
    Location
    Campton Hills, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: try to Copy entire Row if active cell equals variable

    I changed that, but still does the same thing. It will run and do exactly what it's supposed to but only for the first payroll date on the sheet.

  28. #28
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: try to Copy entire Row if active cell equals variable

    Not sure what else to do....Create a new sample with a few of your current entries and test the code again....Also upload so that we can test. See if there is a difference.
    Edit:

    Herewith code that solves this Threads issue.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Sintek; 04-26-2017 at 03:11 PM.

+ 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] Macro to search Active cell, then copy entire row & sort the list
    By teaboi in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-08-2016, 09:50 AM
  2. [SOLVED] Return entire row if cell equals
    By Moedeb27 in forum Excel General
    Replies: 5
    Last Post: 08-03-2016, 07:28 PM
  3. Replies: 3
    Last Post: 07-16-2015, 09:29 AM
  4. [SOLVED] Copy Entire Row if Cell Value Equals X or Y or Z
    By TShelt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-01-2014, 04:38 PM
  5. Replies: 1
    Last Post: 07-31-2013, 10:21 AM
  6. [SOLVED] Macro to Copy Entire Rows if Column Equals
    By Andrew.Trevayne in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-21-2012, 09:46 PM
  7. Copy Range to New Line - Save Active Cell to Temp Variable
    By ngay528 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-23-2009, 05:00 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