Find the matching values and populate that row VBA

DMO123

Board Regular
Joined
Aug 16, 2018
Messages
99
Hi All,

I am wondering if someone would be able to help. I have been looking online for a similar code for the below but I cannot find anything close. I am looking for a VBA that does the following:

I have data in sheet 4 column “I” if column “H” is blank I need to search in sheet 3 for the matching value in column “I”. If its not in sheet 3 it then needs to look in sheet 2 and again if not there sheet 1. Once it finds the matching value it should copy the matching row from column A:L. paste the value in sheet 4 on the row which triggered the search. After it has pasted the value wherever it copied from it needs to delete that row.

This will need to loop down column “I” in sheet 4 until there is no more to do. If values are already there as in I and H is completed then don’t edit it.

I was using this code that I found but it only searches in one column and my VBA knowledge doesn’t help me in how to change it to a row. But I’m not even sure this will work either. It runs but nothing shows on the excel file.

Sub CopyRng2()

Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim Rng As Range
Dim Col As Long
Dim i As Long

On Error Resume Next 'Without this macro crashes if there's no match

Set WS1 = Sheets("Sheet4")
Set WS2 = Sheets("Sheet1")

Set Rng = WS1.Range("A:I")

With WS2
'Finds the column to copy:
Col = Application.WorksheetFunction.Match(WS1.Range("I").Value, .Rows("1:1"), False)
'Write the values individually:
For i = 1 To 5
.Cells(Choose(i, 1, 30, 15, 2, 9), Col).Value = Rng.Cells(i).Value
Next i
End With

End Sub

Any help would be appreciated!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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