+ Reply to Thread
Results 1 to 13 of 13

building a macro that moves entire row of data based on criteria look up in three columns

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    Alberta, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    building a macro that moves entire row of data based on criteria look up in three columns

    Hello,

    Please be patient with me. I am new to Macro's, I have taken basic programming of C++ but I am having trouble understanding this macro language
    I have come across a request to build a macro that would move entire row of data from one sheet to a seperate sheet based on a single word criteria of three columns in the original sheet.
    The three columns will have one of three responses in the cells (Current, DUE, or 'blank'). Any row with the work 'DUE' in any of the three columns will get transferred to the next page.

    I would be really grateful for your knowledge in this matter.
    Thank you

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: building a macro that moves entire row of data based on criteria look up in three colu

    Do you want the movement to happen as soon as the value is populated or on the click of a button?

    Should all 3 columns have the same value?

    Why dont you attach a sample file?

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: building a macro that moves entire row of data based on criteria look up in three colu

    Hello there,

    Could you please upload a sample workbook?

    Thanks!

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: building a macro that moves entire row of data based on criteria look up in three colu

    Hi,

    In essence this boils down to filtering your data.
    Assuming your data is contiguous and in Sheet1 columns labelled 'A', 'B' & 'C' with the data in A2:Cn where n is the last row of your data.

    In Sheet1 enter in E1:G1 the letters 'A', 'B' & 'C'
    In E2, F3 & G4 enter the word "DUE"

    In Sheet2, the output sheet enter 'A', 'B' & 'C' in A1, B1 & C1

    Now your macro is
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    09-11-2012
    Location
    Alberta, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: building a macro that moves entire row of data based on criteria look up in three colu

    AHS test.xlsx

    Ok here is my sample. Hope it works

  6. #6
    Registered User
    Join Date
    09-11-2012
    Location
    Alberta, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: building a macro that moves entire row of data based on criteria look up in three colu

    I would like the movement to happen as soon as the list is populated, or if need be a button could be created to run the script.
    The three columns could have one of three responses (Current, DUE or 'blank') but I am only really concerned about the DUE.

    Thanks again everyone for your patience!!

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: building a macro that moves entire row of data based on criteria look up in three colu

    See attached. Just click the big blue button on the Due Screening sheet.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    09-11-2012
    Location
    Alberta, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: building a macro that moves entire row of data based on criteria look up in three colu

    HI Richard,
    That is great but I cant read it.

    So "data" is what you are looking up?
    "DataOut" is where you want the data to go?
    "Crit" is the row?

    Where are these defined?
    Sorry dont get me wrong, I love that this works but I want to understand it more.

    [Range("Data").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("DataOut"), CriteriaRange:=Range("Crit")]

    Cheers,
    N

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: building a macro that moves entire row of data based on criteria look up in three colu

    Hi,

    It's always good practice to use named ranges for all sorts of reasons rather than cell references like A1:B2, not least because they are more immediately understandable.

    In addition if a range of data is likely to change in its number of rows, (which is usually the case), then it makes even more sense to make that name what we call a dynamic range name. If you look in the Formulas tab you'll see exactly how the range name 'Data' is defined.

    The 'DataOut' range name is simply the column header labels from your data that you want to use in your results sheet.

    The 'Crit' Range name is the range of cells that contain the selection criteria that you want to use to identify the rows that should be filtered and copied. In your case they are 'OR' conditions, i.e. the word Due can be in any column, hence the criteria range needs to be spread across three rows 2:4. Had you wanted the 'AND' condition where all three columns MUST contain the word Due you would have put the criteria word 'Due' on the same row in each criteria column.

  10. #10
    Registered User
    Join Date
    09-11-2012
    Location
    Alberta, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: building a macro that moves entire row of data based on criteria look up in three colu

    Hi Richard,

    This seems like good logic but I cant figure out how you named the ranges.
    I have also just converted from an IBM to a MAC, so the learning curve is pretty steep at the moment, but I am still plugging away at figuring out the excel mac version to figure out the named ranges that you used! All is good.

    Thank you for your input. It seems to work well!

  11. #11
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: building a macro that moves entire row of data based on criteria look up in three colu

    Quote Originally Posted by Nicklebach View Post
    ....
    I have also just converted from an IBM to a MAC, so the learning curve is pretty steep at the moment, but I am still plugging away at figuring out the excel mac version to figure out the named ranges that you used! All is good.
    You have my sympathy. I'm a devout supporter of all things Mac and use a Macbook for many things - with the significant exception of Excel. I find the Mac version of Excel is just too clunky and difficult to work with. Particularly when it comes to macros & VBA where not only is some of the syntax different but also the Visual Basic editor which is nowhere as near efficient as the Windows version and makes developing and debugging code extremely tedious. So for any serious developments I always use Excel for Windows.

  12. #12
    Registered User
    Join Date
    09-11-2012
    Location
    Alberta, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: building a macro that moves entire row of data based on criteria look up in three colu

    Hi Richard,
    I'm Back
    I need your ever patient and talented help please.
    1) I broke the macro. I changed the criteria and added three individual filter tests. none of them seem to work, or bring over what I am asking them to do. So frustrated and such a beginner with macros. Please be patient with me :-)

    2) Is it possible to build the Macro based on an inputed value from the user? For example, lets say there are too many people with Cervical 'Due' exams, can we add another criteria of lets say their birthmonth. User would press the filter data and get prompted for a birth month, then the rows specific to those who are due would get moved over to a seperate sheet.

    3) I need to create mail merge letters from the filtered sheets. Can you create a macro to make a mail merge? I need to build these files as templates, as long as the excel and word document are in the same file location. This should work, no?

    I appreciate your guidance through this, I am still on a Mac, although surviving, I am pretty frustrated.

    Cheers,
    N
    AHS test-1.xlsm
    Claresholm Medical Clinic Letter.docx
    Last edited by Nicklebach; 09-23-2012 at 07:12 PM.

  13. #13
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: building a macro that moves entire row of data based on criteria look up in three colu

    Hi,

    Unfortunately I'm unable to respond in detail just at the moment - see my PM.

    It is of course possible to do all you want with a macro so hopefully someone should be along to help before long.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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