VBA to cut entire row based on text in cell and paste to new sheet

shanegu01

New Member
Joined
Dec 8, 2019
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Looking to cut content of entire row based on whether cell in column 'D' (date completed) has a date in it. If so, need to lookup date in column 'B' (Date received) and paste content of row into first available row in the worksheet for that month/year.
E.g. row 3 in example below has a date in the 'date completed' cell, so need to cut entire row and lookup to check date in the 'Date received' column (in this case Jan 2020) and paste in worksheet titled 'Jan 2020'. Need to search through each row and do the same function.

1575867775251.png
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Welcome to the MrExcel board!

Try this in a copy of your workbook. It assumes that any required monthly sheets already exists.

VBA Code:
Sub MoveCompleted()
  Dim rw As Range
  
  With Sheets("data").Range("A1").CurrentRegion
    .AutoFilter Field:=5, Criteria1:="<>"
    For Each rw In .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible).Rows
      rw.Copy Destination:=Sheets(Format(rw.Cells(5), "mmm yyyy")).Range("E" & Rows.Count).End(xlUp).Offset(1, -4)
    Next rw
    .Offset(1).EntireRow.Delete
    .AutoFilter
  End With
End Sub

BTW, for the future, you will faster & better help if you provide your sample data in a format that can be copied for testing. My signature block below has help with that. You would realise that helpers want to help, not type out data. ;)
 
Upvote 0
Hi Peter_SSs

Thanks for the code. It mostly worked. What's missing is the pasting of the rows into the respective worksheets based on the data in column 'C' - Date Received date. The way you made it work is based on the date in column 'E' - Date completed. Is this possible
 
Upvote 0
Ah, yes sorry. I did read that but I was tricked by your image showing only sheets for Jan & Feb 2020 which were the 'Completed' months. To use the date from column C, just make this change
Rich (BB code):
rw.Copy Destination:=Sheets(Format(rw.Cells(3), "mmm yyyy")).Range("E" & Rows.Count).End(xlUp).Offset(1, -4)
But remember those monthly sheets must already exist in the workbook for my code to work as it is at the moment.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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