delete new items in sheet and arrange again to put into adjacent cells

MKLAQ

Active Member
Joined
Jan 30, 2021
Messages
415
Office Version
  1. 2016
Platform
  1. Windows
Hi
I want matching items in column B between two sheets . if the item is existed in first sheet but not existed in second sheet then should delete the new item from first sheet and should arrange again to put each item for firs sheet is adjacent cell for second sheet
my data could be 5000 rows.
R (1).xlsm
AB
1ITEMGOODS
21QQW-13 CLA13 TR
32QQW-10 BN CLA10 IT -MM
43QQW-11 LVD CH
54 CR CCR-1
65QQW-12 CLA12 JA
76CCR-2
87CCM
98CCB-2
109TR CCB-3
1110CCV-9
1211CCB-1
1312QQW-8 CLA8 UK
1413QQW-9 CLA9 N BR
1514QQW-10 BN CLA10 IT
1615CVF8
1716 CR CCR-1
1817QQW-13 CLA11 TR
1918TR CCB-3
2019QQW-14 L/R CLA14 SS230 EG
2120QQW-15 CLA5 EG
SDE



R (1).xlsm
ABCD
1ITEMGOODSQTY1QTY2
21 CR CCR-1 121
32QQW-10 BN CLA10 IT -MM6611
43QQW-11 LVD CH7711
54QQW-12 CLA12 JA8822
65CCR-2 4522
76CCB-2 111
87TR CCB-3 4411
98CCB-1 1211
109QQW-8 CLA8 UK1211
1110QQW-9 CLA9 N BR3322
1211QQW-10 BN CLA10 IT4422
1312 CR CCR-1 120345
1413TR CCB-3 236
1514QQW-13 CLA13 TR9933
1615QQW-13 CLA11 TR6644
1716QQW-14 L/R CLA14 SS230 EG3322
1817QQW-15 CLA5 EG2222
FGH



result

R (1).xlsm
AB
1ITEMGOODS
21 CR CCR-1
32QQW-10 BN CLA10 IT -MM
43QQW-11 LVD CH
54QQW-12 CLA12 JA
65CCR-2
76CCB-2
87TR CCB-3
98CCB-1
109QQW-8 CLA8 UK
1110QQW-9 CLA9 N BR
1211QQW-10 BN CLA10 IT
1312 CR CCR-1
1413TR CCB-3
1514QQW-13 CLA13 TR
1615QQW-13 CLA11 TR
1716QQW-14 L/R CLA14 SS230 EG
1817QQW-15 CLA5 EG
SDE
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I am not understand what it means: "arrange again to put each item for firs sheet is adjacent cell for second sheet"
But below code yields exactly your expected output:
VBA Code:
Option Explicit
Sub test()
Dim lr&, i&, k&, rng, arr(1 To 10000, 1 To 2), searchRange As Range
With Worksheets("SDE")
    lr = .Cells(Rows.Count, "B").End(xlUp).Row
    Set searchRange = .Range("B2:B" & lr)
End With
With Worksheets("FGH")
    lr = .Cells(Rows.Count, "B").End(xlUp).Row
    rng = .Range("A2:B" & lr).Value
    For i = 1 To lr - 1
        If WorksheetFunction.CountIf(searchRange, rng(i, 2)) Then
            k = k + 1
            arr(k, 1) = rng(i, 1): arr(k, 2) = rng(i, 2)
        End If
    Next
End With
With Worksheets("SDE")
    .Range("A2:B10000").ClearContents
    .Range("A2").Resize(k, 2).Value = arr
End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,885
Messages
6,175,181
Members
452,615
Latest member
bogeys2birdies

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