Match issue

rollingzep

Board Regular
Joined
Nov 18, 2013
Messages
224
Office Version
  1. 365
Platform
  1. Windows
Hi,

I do a Match between two workbooks. It works fine.
The field in first WB looks at Col A or Col B and returns values from col C of the second WB.
I now need a third condition. If there are no matches, then it should be "NA".
How to do this?


VBA Code:
       Data = .Value
        With wbexcelEXT.Sheets("HQ").Cells(1).CurrentRegion
            For i = 2 To UBound(Data)
                Chk = Application.Match(Data(i, 33), .Columns(1), 0)
                If IsError(Chk) Then
                    Chk = Application.Match("*" & Data(i, 33) & "*", .Columns(2), 0)
                End If
                If Not IsError(Chk) Then Data(i, 55) = .Cells(Chk, 3)
            Next i
        End With
        .Value = Data
    End With
    ws.Range("BC:BC").NumberFormat = "@"
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Usually my practice in such cases is:
VBA Code:
  Dim Chk As Range

  Set Chk = .Columns(1).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
  If Not Chk Is Nothing Then
    Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(1), 0), 3)
  Else
    'Do something here if no matches
  End If
 
Upvote 0
Usually my practice is in such cases:
VBA Code:
  Dim Chk As Range

  Set Chk = .Columns(1).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
  If Not Chk Is Nothing Then
    Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(1), 0), 3)
  End If
Thanks. But I do need to add the value "NA", if there is no match between 33 of WB 1 and col1 and col2.
I need a condition like, Data(i, 55) = "NA"
The analysts will look for these NA and fill the correct value.
 
Upvote 0
How about this:
VBA Code:
  Dim Chk1 As Range, Chk2 As Range

  Set Chk1 = .Columns(1).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
  Set Chk2 = .Columns(2).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
  If Not Chk1 Is Nothing Then
    Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(1), 0), 3)
  ElseIf Not Chk2 Is Nothing Then
    Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(2), 0), 3)
  Else
    Data(i, 55) = "NA"
  End If
 
Upvote 0
How about this:
VBA Code:
  Dim Chk1 As Range, Chk2 As Range

  Set Chk1 = .Columns(1).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
  Set Chk2 = .Columns(2).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
  If Not Chk1 Is Nothing Then
    Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(1), 0), 3)
  ElseIf Not Chk2 Is Nothing Then
    Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(2), 0), 3)
  Else
    Data(i, 55) = "NA"
  End If
I get syntax error on the Set line
VBA Code:
    With wbexcel.Sheets("TSS Fails").Cells(1).CurrentRegion.Resize(, 45)
        Data = .Value
        With wbexcelEXT.Sheets("HQLA").Cells(1).CurrentRegion
            For i = 2 To UBound(Data)
       [B]Set Chk = .Columns(1).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)[/B]
        If Not Chk Is Nothing Then
          Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(1), 0), 3)
        Else
          Data(i, 55) = "NA"
        End If
            Next i
        End With
        .Value = Data
    End With
 
Upvote 0
VBA Code:
  Dim Chk1 As Range, Dim Chk2 As Range

  With wbexcel.Sheets("TSS Fails").Cells(1).CurrentRegion.Resize(, 45)
    Data = .Value
        With wbexcelEXT.Sheets("HQLA").Cells(1).CurrentRegion
        For i = 2 To UBound(Data)
         Set Chk1 = .Columns(1).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
         Set Chk2 = .Columns(2).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
         If Not Chk1 Is Nothing Then
           Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(1), 0), 3)
         ElseIf Not Chk2 Is Nothing Then
           Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(2), 0), 3)
         Else
           Data(i, 55) = "NA"
         End If
        Next i
        End With
        .Value = Data
    End With
 
Upvote 0
VBA Code:
  Dim Chk1 As Range, Dim Chk2 As Range

  With wbexcel.Sheets("TSS Fails").Cells(1).CurrentRegion.Resize(, 55)
    Data = .Value
        With wbexcelEXT.Sheets("HQLA").Cells(1).CurrentRegion
        For i = 2 To UBound(Data)
         Set Chk1 = .Columns(1).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
         Set Chk2 = .Columns(2).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
         If Not Chk1 Is Nothing Then
           Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(1), 0), 3)
         ElseIf Not Chk2 Is Nothing Then
           Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(2), 0), 3)
         Else
           Data(i, 55) = "NA"
         End If
        Next i
        End With
        .Value = Data
    End With
I am still getting syntax errors on the two Set line of codes.
Set Chk1 = .Columns(1).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
Set Chk2 = .Columns(2).Find(what:Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
I have the following references
1681937403903.png
 
Upvote 0
Sorry I had missing equal marks:
VBA Code:
  Dim Chk1 As Range, Chk2 As Range

  With wbexcel.Sheets("TSS Fails").Cells(1).CurrentRegion.Resize(, 45)
    Data = .Value
        With wbexcelEXT.Sheets("HQLA").Cells(1).CurrentRegion
        For i = 2 To UBound(Data)
         Set Chk1 = .Columns(1).Find(what:=Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
         Set Chk2 = .Columns(2).Find(what:=Data(i, 33), LookIn:=xlFormulas, lookat:=xlWhole)
         If Not Chk1 Is Nothing Then
           Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(1), 0), 3)
         ElseIf Not Chk2 Is Nothing Then
           Data(i, 55) = .Cells(Application.Match(Data(i, 33), .Columns(2), 0), 3)
         Else
           Data(i, 55) = "NA"
         End If
        Next i
        End With
        .Value = Data
    End With
 
Upvote 0
Solution

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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