Cut paste entire row to new sheet

micko1

Board Regular
Joined
Feb 10, 2010
Messages
80
I have a workbook that keeps track of sub contractors and thier compliance to insurances etc. I have a column in sheet "Regional Contractors) that has an if/or formula =IF(OR(F8<=TODAY(),G8<=TODAY(),H8<=TODAY()),"NonCompliant","") This formula is in column "O" starting in row 7. I have a named this range and called it "NonCompliant". I am trying to write a macro that will check the named range and cut any row it finds that equals NonCompliant and then paste it to a new sheet called "NonCompliant" starting from A7. The macro needs to look for the next vacant row in WS "NonCompliant" each time the button is pressed to ensure entries are not over writen. This is a sample of the code I have started with. It finds the correct rows, cuts and paste them to the new sheet and then deletes the empty rows on the original. Problem is if another entry becomes noncompliant and it needs to be moved to the second sheet "NonCompliant" it does not paste to a blank row.
Sorry to rave on and thanks for any help in advance.

Private Sub CommandButton1_Click()
Dim Ccell As Range
Dim Ws As Worksheet
Dim RowCounter() As Long
Dim r As Long
ScreenUpdating = False
ReDim RowCounter(Sheets.Count)
Application.ScreenUpdating = False
For Each Ws In Worksheets
RowCounter(Ws.Index) = 7
For Each Ccell In Range("Noncompliant") 'Sheetname defined in Excel names
If Ws.Name = Ccell.Value Then
Ccell.EntireRow.Cut
ActiveSheet.Paste Destination:=Sheets(Ws.Name).Cells(RowCounter(Ws.Index), 1)
RowCounter(Ws.Index) = RowCounter(Ws.Index) + 1
End If
Next
Next

For r = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
If Cells(r, 1) = "" Then Rows(r).Delete
Next r
ScreenUpdating = True

End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,224,521
Messages
6,179,278
Members
452,902
Latest member
Knuddeluff

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