[HELP] How to marco to cut Entire row to new sheet if cell data matched

harky

Active Member
Joined
Apr 8, 2010
Messages
405
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
I got this code from one of the thread here.. need pro here to guide me along :)

this code cut Entire row to new sheet but this code is gd if i dont have much data to cut and paste.
but What i want is,

is it possible Match P/N in Excel 2 with Masterdata (excel 1) P/N column and cut the entire row in Masterdata (excel 1) to another new excel?

Masterdata (excel 1)
P/N
DESP
Price
Discount Price
001APPLE10.00
9.00
002APPLE10.00
9.00
003APPLE9.00
8.00
004BANANA8.00
7.00
005CHERRY10.00
9.50
006CHERRY8.00
7.50
007DURIAN5.00
4.00
008ORANGE4.00
3.00
009ORANGE8.00
2.00

<tbody>
</tbody>

Match P/N (excel 2)
P/N
001
002
003
004
005
006
007
008
009

<tbody>
</tbody>




Code:
Sub test()  Dim WSD As Worksheet  Application.ScreenUpdating = False  Set WSD = Worksheets("Sheet2")  WSD.Cells.Clear With ActiveSheet.UsedRange     LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column     Cells(2, LastColumn + 2).FormulaR1C1 = "=MATCH(RC2,{""Apple"",""Cherry"",""Orange""},0)"     .AdvancedFilter Action:=xlFilterInPlace, criteriarange:=Cells(1, LastColumn + 2).Resize(2, 1)     .Copy Destination:=WSD.Cells(1, 1)     On Error Resume Next     .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).SpecialCells(xlCellTypeVisible).EntireRow.Delete     If Err.Number <> 0 Then         MsgBox "No records found..."         WSD.Rows(1).Delete         On Error GoTo 0     End If End With  ActiveSheet.ShowAllData Columns(LastColumn + 2).Clear  Application.ScreenUpdating = True  End Sub</pre>
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
here the code

Code:
Sub DSDSD()

Dim WSD As Worksheet

Application.ScreenUpdating = False

Set WSD = Worksheets("Sheet2")

WSD.Cells.Clear
With ActiveSheet.UsedRange
    LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
    Cells(2, LastColumn + 2).FormulaR1C1 = "=MATCH(RC2,{""Apple"",""Cherry"",""Orange""},0)"
    .AdvancedFilter Action:=xlFilterInPlace, criteriarange:=Cells(1, LastColumn + 2).Resize(2, 1)
    .Copy Destination:=WSD.Cells(1, 1)
    On Error Resume Next
    .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    If Err.Number <> 0 Then
        MsgBox "No records found..."
        WSD.Rows(1).Delete
        On Error GoTo 0
    End If
End With

ActiveSheet.ShowAllData
Columns(LastColumn + 2).Clear

Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,048
Messages
6,122,862
Members
449,097
Latest member
dbomb1414

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