match cell with column and copy entire rows from sheet to another

Ali M

Active Member
Joined
Oct 10, 2021
Messages
287
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hello
I need help from experts to help me how adapt this code for my requirements .
I have sheet1 is target and contains cell B2 should fill the name and the others data start from A4:G , the row4 is the headers . the name in cell B2 should match with column G for DATA sheet (DATA sheet start from A1: G , the row1 is header ) if they are matched ,then should copy data without any formatting form DATA sheet to target sheet(sheet1) from row 5 , but shouldn't copy to the bottom , just replace data .


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim Fnd As Range
   Dim sh As Worksheet
   Set sh = Sheets("DATA")
   If Target.Count > 1 Then Exit Sub
   If Target.Address(0, 0) = "B2" And Target.Value <> "" Then
      Set Fnd = sh.Range("G:G").Find(Target.Value, , , xlWhole, , , False, , False)
      If Not Fnd Is Nothing Then
         sh.Cells.EntireRow.Copy Target.Cells(Rows.Count, 1).End(xlUp).Offset(1)
      Else
         MsgBox Target.Value & " not found"
      End If
   End If
End Sub
thanks
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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