move entire row containing a target value

JimmyG64

New Member
Joined
Nov 16, 2018
Messages
4
Hello,

I've been able to find solutions that are close, but not exact I need a macro that will autorun when the spreadsheet ("data") opens and looks for a target value ("no"), then moves (not copy) the rows that contain the target to another sheet ("Has_No").

The code below only looks for the target in column c, not the whole row. I know it's probably a simple solution for most of you but I can't figure it out.

Thanks in advance and please gentle with the new guy.

Sub Has_No()
Dim xRg As Range
Dim xCell As Range
Dim I As Long
Dim J As Long
Dim K As Long
I = Worksheets("Data").UsedRange.Rows.Count
J = Worksheets("Has_No").UsedRange.Rows.Count
If J = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Has_No").UsedRange) = 0 Then J = 0
End If
Set xRg = Worksheets("Data").Range("C1:C" & I)
On Error Resume Next
Application.ScreenUpdating = False
For K = 1 To xRg.Count
If CStr(xRg(K).Value) = "No" Then
xRg(K).EntireRow.Copy Destination:=Worksheets("Has_No").Range("A" & J + 1)
xRg(K).EntireRow.Delete
If CStr(xRg(K).Value) = "No" Then
K = K - 1
End If
J = J + 1
End If
Next
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try to replace
Code:
[COLOR=#333333]Set xRg = Worksheets("Data").Range("C1:C" & I)[/COLOR]

by
Code:
set xRg=[COLOR=#333333]Worksheets("Data").Range(cells(1,3),cells(I,[/COLOR][COLOR=#333333]Worksheets("Data").UsedRange.Columns.Count[/COLOR][COLOR=#333333]))[/COLOR]
 
Upvote 0
Thank you for responding. It still only moves the row when "No" is in column c. The goal is for it to move the row if "now" appears in any column in that row.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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