Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski 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
Joined
Mar 17, 2013
Messages
19
Location
DE
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
 
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

Back
Top