Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

modify formula Index Match in Macro to "go to next" if match not found

Status
Not open for further replies.

HawksOkeyoJr

New member
Mar 17, 2013
19
I will highly appreciate your help.
I have this code which searches and Match corresponding column with exact values from another workbook. to make it more clear, in WB1 i have two columns a:a and b:b with data and on the other WB2 same BUT with more data in column a:a. all the data in column a:a WB1 are in WB2 column a:a but not the other way round.
My code searches and matches and copy paste the exact data from the two WB's but the only thing it doesn't do is to Skip the data which are in WB2 but absent in WB1.
can somebody help me modify this code to skip this cells and go to next OR if you have a better code, can you help.
Thank you. Here is the Macro that i am using at the moment.

Dim DataFile, WorkingFile As Workbook
Dim DataLastRow, WorkingLastRow As Double
'Turn off screen updating
Application.ScreenUpdating = False
'Open the combined file
Windows("CopyAllHere.xlsm").Activate
ThisWorkbook.Worksheets("4525003").Select
'---------------------------------
Set DataFile = ActiveWorkbook
'---------------------------
DataLastRow = Range("A65536").End(xlUp).Row
'-----------------------------
Workbooks.Open Filename:="H:\A350_PREPS\Macro\Strain_Prediction_FST_All_LCs_using_DFEMs_v2.xls"
Set WorkingFile = ActiveWorkbook
Worksheets("4525003").Select
WorkingLastRow = Range("A65536").End(xlUp).Row
On Error Resume Next
Range("B2:B" & WorkingLastRow).Formula = _
"=INDEX(" & DataFile.Name & "!B$2:B" & DataLastRow & ",MATCH($A$2:$A$" & WorkingLastRow & _
"," & DataFile.Name & "!$A$2:$A$" & DataLastRow & ",0))"
On Error GoTo 0

Range("B2:B" & WorkingLastRow).Copy
Range("B2:B" & WorkingLastRow).PasteSpecial xlPasteValues

Application.CutCopyMode = False
'Turn on screen updating
Application.ScreenUpdating = True
End Sub
 
Replies continue below

Recommended for you

Have you tried an if statement in a loop?
For example:
If WB2.cell(x,1) = "" then
WB2.cell(x,1) = WB2.cell(x,1)
end if
x = x+1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor