+ Reply to Thread
Results 1 to 4 of 4

Transfer Data from one sheet to 2 other sheets based on criteria gets stuck mid-sub

  1. #1
    Registered User
    Join Date
    11-09-2009
    Location
    Mallorca, Spain
    MS-Off Ver
    Excel 2007
    Posts
    2

    Transfer Data from one sheet to 2 other sheets based on criteria gets stuck mid-sub

    I have an excel workbook with three sheets named "PROSPECTS", "CLIENTS" and "NO GO" and I have been trying to write a vba sub which moves rows from the "Prospects" sheet to the "Clients" and "No Go" sheets based upon criteria in one column (which I have tagged status) and then delete the empty rows in the "Prospects" sheet. All three sheets have the same headers which occupy two rows.

    Once it is all working, I would then add to the "Prospects" sheet on a daily basis and update the "Clients" and "No Go" sheets with a command button which calls my vba routine. I have created a vba sub to do this but it gets stuck half way through and I can not get it to work. Can anybody help please.

    My command button sub is as follows:

    Private Sub CommandButton1_Click()

    a = Worksheets("PROSPECTS").Cells(Rows.Count, 1).End(xlUp).row

    ' Prevents screen refreshing.
    Application.ScreenUpdating = False

    For i = 3 To a

    If Worksheets("PROSPECTS").Cells(i, 29).Value = "ON RISK" Then

    Worksheets("PROSPECTS").Rows(i).Cut
    Worksheets("CLIENTS").Activate
    b = Worksheets("CLIENTS").Cells(Rows.Count, 1).End(xlUp).row
    Worksheets("CLIENTS").Cells(b + 1, 1).Select
    ActiveSheet.Paste
    ActiveSheet.Columns(29).EntireColumn.Delete
    Worksheets("PROSPECTS").Activate

    ElseIf Worksheets("PROSPECTS").Cells(i, 29).Value = "DID NOT PROCEED" Then

    Worksheets("PROSPECTS").Rows(i).Cut
    Worksheets("NO GO").Activate
    c = Worksheets("NO GO").Cells(Rows.Count, 1).End(xlUp).row

    Worksheets("NO GO").Cells(c + 1, 1).Select
    ActiveSheet.Paste [THIS IS WHERE THE ROUTINE STOPS]
    ActiveSheet.Columns(29).EntireColumn.Delete
    Worksheets("PROSPECTS").Activate

    End If

    Next i

    Application.CutCopyMode = False
    ThisWorkbook.Worksheets("PROSPECTS").Cells(1, 1).Select

    Call delete_blank_rows

    End Sub

    The delete_blank_rows sub which is called for is in Module 1 and is as follows:

    Sub delete_blank_rows()
    Dim row As Long
    LastRow = ThisWorkbook.Sheets("PROSPECTS").Cells(Rows.Count, 1).End(xlUp).row
    row = 3
    For row = LastRow To row Step -1
    If Cells(row, 1) = "" Then
    Cells(row, 1).EntireRow.Delete
    End If
    Next row
    End Sub

    In the “Prospects” sheet, the prospects become clients or no go at different speeds and so the criteria for moving though always in column 29 (column “AC”) can be mixed in different rows. I have indicated where the routine stops. It does transfer the rows marked as clients in column 29 but stops when it comes to one which is marked “ONGOING”. Since all “NO Go” rows and some of the “Clients” rows are below that point it does nothing to them.

    I am stuck. I would be most grateful for assistance please.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: Transfer Data from one sheet to 2 other sheets based on criteria gets stuck mid-sub

    Try this macro on a copy of your file:
    Please Login or Register  to view this content.
    Last edited by Mumps1; 10-08-2018 at 03:19 PM.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    11-09-2009
    Location
    Mallorca, Spain
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Transfer Data from one sheet to 2 other sheets based on criteria gets stuck mid-sub

    Hello Mumps 1,

    First of all thank you for your input. Unfortunately your macro did not work, it gave me a Run-time error 1004 with the
    caption ‘cannot change part of a merged cell’ . The only merged cells in my model are in the headers which occupy rows 1 and 2
    of each of the 3 sheets.

    This may be because I did not explain clearly the object of the exercise.
    In any event, my ‘Prospects’ sheet is the main input sheet and the data rows extend from row 3 to any number.
    There are 29 columns of data. The 29th column (AC) is a status column. All entries start as Prospects and commence
    with the status as ‘Ongoing’. At a certain point they are then designated as ‘Clients’ or No Gos and should with the
    click of the Commandbutton, they should be transferred to their respective sheets. All new transfers to those two sheets
    should append the new rows to the first empty rows in those sheets. Since the 29th status column is not needed in the Clients
    and No Go sheets, it should be deleted on both the Clients and No Go sheets once the rows have been transferred.

    Going back to the Prospects sheet, the resulting empty rows on the Prospects sheet should be deleted and only those
    rows with the status in column 29 as ‘Ongoing’ should remain

    In this way each of the sheets become ongoing and dynamic records of Prospects, Clients and No Gos respectively.

    I hope that makes it more clear.

    Thank you again for your input and I would really appreciate any additional help you can provide

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: Transfer Data from one sheet to 2 other sheets based on criteria gets stuck mid-sub

    In my tests, the macro does exactly what you want. The problem is being caused by the merged cells. You should avoid using merged cells at all cost because they create havoc for Excel macros. You will have to unmerge all the merged cells. Do a little research into "Center Across Selection". Most often this will have the same effect as merging cells without actually having to merge them. If you can attach a copy of your file, I can have a closer look. If it contains any confidential information, you can replace it with generic data.

+ 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. Copy and transfer data from a Main sheet to two sheets based on two conditions
    By Joky in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 07-30-2017, 02:22 PM
  2. Transfer data based on value in Column from sheet to two sheets using arrays
    By salmasaied in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-10-2016, 10:01 PM
  3. [SOLVED] Transfer Cell Data From 1 Sheet To Another Based on Criteria
    By thecircularwriter in forum Excel General
    Replies: 10
    Last Post: 01-24-2016, 04:46 PM
  4. Pulling Data from a sheet based on criteria on both those sheets
    By mlbdc2012 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-06-2015, 07:46 PM
  5. Pulling Data from a sheet based on criteria on both those sheets
    By mlbdc2012 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-06-2015, 10:39 AM
  6. [SOLVED] Want to Distribute Data from Sheet A to the other sheets based on Criteria
    By jordan1214 in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 04-13-2013, 09:27 PM
  7. Macro to transfer row of data between sheets based on certain criteria.
    By kmc86 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-26-2012, 10:40 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