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.
Bookmarks