+ Reply to Thread
Results 1 to 4 of 4

Copying rows from worksheet to another worksheet based on condition

  1. #1
    Registered User
    Join Date
    01-30-2012
    Location
    Port of Spain, Trinidad
    MS-Off Ver
    Excel 2010
    Posts
    10

    Copying rows from worksheet to another worksheet based on condition

    I am very new to Excel VBA, actually this my first attempt. I have looked at a lot of videos and googled it but I need some help.

    I have two worksheets which are similar. One is called Morning and the other Evening.
    In the Morning worksheet, there is a NameRange called MorningRange (the range is from B12:O47). In the Evening worksheet, there is a NameRange called EveningRange (the range is from B12:O47). In each there are eight columns.

    I want to do two things.

    I want to copy all the rows from the Morning worksheet to Evening worksheet if Status in column F is "Incomplete". However, it should first delete any information that is in EveningRange of Evening worksheet.

    The second thing I want to do is to execute this code from a command button placed on the Morning worksheet. If the user presses it more than once it should simply overwrite what is in the Evening worksheet (EveningRange)

    Can someone please assist me in getting started with this code.

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: Copying rows from worksheet to another worksheet based on condition

    Hi Mokaman10,
    Welcome to the forum!

    Try the following code:
    Please Login or Register  to view this content.
    To run this off a command button, simply call this macro in the CommandButton_Click() event.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-30-2012
    Location
    Port of Spain, Trinidad
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Copying rows from worksheet to another worksheet based on condition

    Thank you jewelsharma,
    The code works like charm when I Run it from the toolbar. However when I try to run it from the Command button I am getting the following:

    Compile error:

    Sub or a Function not defined


    I checked and I have Tool -> Reference and Solver already ticked.

    Any idea why I am getting this error?

  4. #4
    Registered User
    Join Date
    01-30-2012
    Location
    Port of Spain, Trinidad
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Copying rows from worksheet to another worksheet based on condition

    Further to my last query, I had placed the code in ThisWorkbook as I assumed that was where to place it. Was this correct? I remember when I first googled this it said to put the code in Insert module which I just did and Now it is working from the command button. I have no idea why so can you guide me on this?

    Do I have to put it in ThisWorkbook and also Insert module and if so, why?

+ 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 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
  2. Copy Rows to another Worksheet Based on a Condition
    By patxlb in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-06-2013, 04:57 PM
  3. Replies: 3
    Last Post: 11-29-2012, 06:05 AM
  4. Copy Rows to another Worksheet Based on a Condition
    By pbebow in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-22-2012, 07:40 PM
  5. Macro to copy rows to another worksheet based on condition
    By wthomas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2012, 01:11 PM
  6. Replies: 4
    Last Post: 08-16-2011, 09:32 PM
  7. Copy Selected Cells of Rows to another Worksheet Based on a Condition
    By Al53 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2010, 10:33 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