Simple Macro to cut and paste based on cell value

norts55

Board Regular
Joined
Jul 27, 2012
Messages
184
Can anyone share a simple macro that will cut and paste an entire row from one worksheet to another based on part of a cell value within one cell in a certain column? Below I kind of a step by step...

Search Column "C" on worksheet "All" for the word "Time".
Select all (entire) rows that have the word "Time" in column "C"
Cut those selected rows and paste to the top of the worksheet "All Time" - (This worksheet will be empty until the paste occurs)
<o:p></o:p>
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try

Code:
Sub atest()
Dim LR As Long, i As Long
With Sheets("Time")
    LR = .Range("C" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        With .Range("C" & i)
            If .Value = "Time" Then .EntireRow.Cut Destination:=Sheets("All Time").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End With
    Next i
End With
End Sub
 
Upvote 0
Thanks for your help this is greatly appreciated.<o:p></o:p>
<o:p> </o:p>
Ok, this works great except for one thing. I need the search and select to find cells that contain the word "Time" not equal to "Time". Is that possible?<o:p></o:p>
 
Upvote 0
Thanks for the correction Titian :)

Try this for contains Time

Code:
Sub atest()
Dim LR As Long, i As Long
With Sheets("All")
    LR = .Range("C" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        With .Range("C" & i)
            If .Value Like "*Time*" Then .EntireRow.Cut Destination:=Sheets("All Time").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End With
    Next i
End With
End Sub
 
Upvote 0
Again thank you for your help with this. The Macro is working however it is only selecting the first row that contains the word time. I need it to find all rows that contain the word time, then copy and paste all of those. Is that possible?
 
Upvote 0
Where the paste is occuring (sheet all time), yes. Not on the sheet where the selection is happening.
 
Upvote 0
Try

Code:
Sub atest()
Dim LR As Long, i As Long
With Sheets("All")
    LR = .Range("C" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        With .Range("C" & i)
            If .Value Like "*Time*" Then .EntireRow.Cut Destination:=Sheets("All Time").Range("C" & Rows.Count).End(xlUp).Offset(1, -2)
        End With
    Next i
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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