VBA - Find value in sheet and cut paste row on new sheet

kbp

New Member
Joined
May 14, 2012
Messages
36
Hi there

Can someone please help me on this one. Thank you in advance.

Below is a screen dump of the data sheet that I have. The sheet is called "SMT"
What I want to do is:
1. Find the cells on the SMT sheet (in column B always) that contains "12-3113-0003586-002" as value
2. Cut paste the whole row if above value is found
3. Paste into sheet called "SMT02" on A1 cell (SMT02 would be a blank sheet)
4. But if "12-3113-0003586-002" is not found (some days we don't have it), then do nothing.



-- removed inline image ---
 
The image came out a tad blurry.

Here's a guess.

Code:
[color=darkblue]Sub[/color] Copy_Rows()
    [color=darkblue]Dim[/color] strFind [color=darkblue]As[/color] [color=darkblue]String[/color]
    strFind = "*" & "12-3113-0003586-002" & "*"
    [color=darkblue]With[/color] Sheets("SMT")
        [color=darkblue]If[/color] Application.CountIf(.Range("B:B"), strFind) [color=darkblue]Then[/color]
            .Range("B:B").AutoFilter 1, strFind
            .Range("B2", .Range("B" & Rows.Count).End(xlUp)).EntireRow.Copy _
                Destination:=Sheets("SMT02").Range("A1")
            .AutoFilterMode = [color=darkblue]False[/color]
            Sheets("SMT02").Select
        [color=darkblue]Else[/color]
            MsgBox "No match found. "
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
  • Like
Reactions: kbp
Upvote 0

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