Simple Macro to cut and paste based on cell value

norts55

Board Regular
Joined
Jul 27, 2012
Messages
191
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>
 
That works. Thank You!

I have a similar need to the above poster. I tried using the macro that was provided and modifying it to match the conditions in my worksheet but it doesn't seem to work... Here is what I am trying to accomplish.

I have a spreadsheet for work with old tickets on it. The spreadsheet has 2 sheets on it, "open" and "Closed". I have a column, column K where the word Yes will be entered once the ticket has been closed. I would like to have that row cut from the "Open" sheet and pasted to the top of the "Closed" Sheet.

Please feel free to ask any questions if I didn't explain what I need clearly enough, and thank you in advance!
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I understand that VOG has retired now, pehaps you should post the code you have so far and someone may be along later to help
 
Upvote 0
Copied and altered:
Sub atest()
Dim LR As Long, i As Long
With Sheets("Yes")
LR = .Range("K" & Rows.Count).End(xlUp).Row
For i = 1 To LR
With .Range("K" & i)
If .Value Like "*Yes*" Then .EntireRow.Cut Destination:=Sheets("Closed").Range("K" & Rows.Count).End(xlUp).Offset(1, -2)
End With
Next i
End With
End Sub

I don't really know anything about how Macros are written so what I changed may make no sense. When I try to run that I get an error:
Run-time error '9'
Subscript out of range

It points to the following as a problem:
With Sheets("Yes")

Thanks again
 
Upvote 0
Try changing that line to
Code:
With Sheets("Open")
 
Upvote 0
That got me 1 step closer. Now I get the following error:
Run-time error '1004':
This selection isn't valid. Make sure the copy and paste areas don't overlap unless they are the same size.

The highlighted area is in bold below:
If .Value Like "*Yes*" Then .EntireRow.Cut Destination:=Sheets("Closed").Range("K" & Rows.Count).End(xlUp).Offset(1, -2)
 
Upvote 0
Change it to
Code:
If .Value Like "*Yes*" Then .EntireRow.Cut Destination:=Sheets("Closed").Range("K" & Rows.Count).End(xlUp).Offset(1, -10)
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
Hi, I've been reading the forums for a while but have never posted. I have a similar issue and I've tried adjusting my VBA code to suit my needs as well...to no avail.
I have a workbook with sheets listed as months(Jan,Feb<mar,etc). Column M has data validation to select "Yes" or "Ordered" to denote whether product has been given or ordered. I want to search each monthly sheet (there are other sheets that summarize) for any "Ordered" entered into column M and have the data from every other column in that row displayed on a seperate sheet on the workbook (Sheet 2).

This is my "revision" of the code used in this thread...

Code:
Sub LookForOrderedStockings()
Dim LR As Long, i As Long
With Sheets("Ordered")
LR = .Range("M" & Rows.Count).End(xlUp).Row
For i = 1 To LR
With .Range("M" & i)
If .Value Like "*Ordered*" Then .EntireRow.Cut Destination:=Sheet2("Ordered").Range("M" & Rows.Count).End(xlUp).Offset(1, -10)
End With
Next i
End With
End Sub

I run the macro on Sheet 2 and nothing is happening. I currently have 2 "Ordered" cells within my workbook. Any help would be appreciated.
 
Upvote 0
Is there a way to make this macro run automatically (when the workbook is opened), if I can get it to run as intended?
 
Upvote 0

Forum statistics

Threads
1,224,832
Messages
6,181,234
Members
453,026
Latest member
cknader

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