Cut Cells Marked "Closed" and Paste to New Sheet

koolgeex

New Member
Joined
May 2, 2012
Messages
45
1 Workbook
2 Spreadsheets - "Complete Backlog" & "Closed Jobs"
If Column K in "Complete Backlog" says "Closed" then cut that row and paste it into the next available row of "Closed Jobs".

I have this code below but there is an error with it. It currently cuts all of the items marked closed but it doesn't paste all of them on the new sheet.
On my last go around, it cut 34 rows marked Closed and only pasted 20 rows into the new sheet. Suggestions?

Code:
Sub refresh()
Dim LR As Long, i As Long
With Sheets("Complete Backlog")
    LR = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    For i = 1 To LR
        If .Range("K" & i).Value = "Closed" Then .Range("A" & i).Resize(, 11).Cut Destination:=Sheets("Closed Jobs").Range("A" & Rows.Count).End(xlUp).Offset(1)
    Next i
    .Range("A2:K" & LR).SpecialCells(xlCellTypeBlanks).delete shift:=xlShiftUp
End With
End Sub
 
Rich (BB code):
Sub refresh()
Dim LR As Long, i As Long
With Sheets("Complete Backlog")
    LR = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    For i = 1 To LR
        If .Range("K" & i).Value = "Closed" Then .Range("A" & i).Resize(, 11).Cut Destination:=Sheets("Closed Jobs").Range("A" & Rows.Count).End(xlUp).Offset(1)
    Next i
    .Range("A2:K" & LR).SpecialCells(xlCellTypeBlanks).Delete shift:=xlShiftUp
End With
End Sub
Still getting the same error but I did notice it deleted 10 from the main sheet and pasted 7 in the "closed jobs" sheet. Still left 21 marked "close" on the backlog sheet. Man!
The word "closed" and the word "close" are not the same, so you have to look for both of them individually in your test, not just one of them. Try this in your originally posted code (replacing the part I showed in red above)...
Rich (BB code):
If LCase(.Range("K" & i).Value) = "closed" Or LCase(.Range("K" & i).Value) = "close" Then....
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Opps sorry that was a typo. All cells contain "Closed".
Both versions I posted are working fine for me. If all the rows marked "Closed" are being removed from the backlog sheet, but some of them do not appear in the Closed Jobs sheet then the issue is not connected to the If statement. Do you have any hidden rows in the Closed Jobs sheet?
 
Upvote 0
I tried doing it backwards too. Not working for me. I've uploaded it to my web host so you can download and see. Please Please Please take a look. I just don't know what i'm missing. click to download my workbook
 
Upvote 0
Okay, try running your loop backwards then...
Code:
For i = LR To 1 Step -1
That shouldn't make any difference since the delete and shift is done after all data is transferred. I suspect that hidden rows on the receiver sheet may be the problem.
 
Upvote 0
I tried doing it backwards too. Not working for me. I've uploaded it to my web host so you can download and see. Please Please Please take a look. I just don't know what i'm missing. click to download my workbook
Do you have any hidden rows in the receiving area of the completed jobs sheet?
 
Upvote 0
I also just copied the "Complete Backlog" sheet and changed the name to "Closed Jobs" since the headers are the same. I deleted the data and then ran the macro. Still didn't work. I'm using Excel 2003 if that makes a difference. again here's the workbook [here]
 
Upvote 0

Forum statistics

Threads
1,215,111
Messages
6,123,152
Members
449,098
Latest member
Doanvanhieu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top