Need help to fix vba code

ybr_15

Board Regular
Joined
May 24, 2016
Messages
204
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Dear everyone,

I have the code (work properly), like this:
Code:
Sub MyMacro()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim rgnSearch As Range, rngList As Range, rngItem As Range, rngfound As Range
    
    Set ws1 = Sheets("Sheet1")
    Set ws2 = Sheets("Sheet2")
    Set rgnSearch = ws1.Range("A1", ws1.Cells(Rows.Count, 1).End(xlUp))
    Set rngList = ws2.Range("A1", ws2.Cells(Rows.Count, 1).End(xlUp))
    For Each rngItem In rgnSearch
        With rngList
            Set rngfound = .Find(rngItem.Value, LookIn:=xlValues)
            If rngfound Is Nothing Then
                ws2.Cells(Rows.Count, 5).End(xlUp).Offset(1, 0).Resize(, 3).Value = VBA.Array(rngItem.Value, rngItem.Offset(0, 1).Value, rngItem.Offset(0, 2).Value)
            End If
        End With
    Next
End Sub
The above code works to copy missing data of 2 tables compared. When I press button 'Click', the missing data will be copying in E2, like this:
EXCEL_2017-03-23_19-08-07.png

My problem is:
I want to copy the missing data to a new table that I created, but the data cannot be copied start from below header table, like this:
EXCEL_2017-03-23_19-19-37.png

How to fix that problem? Thank you...
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,215,429
Messages
6,124,834
Members
449,192
Latest member
mcgeeaudrey

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