Excel If statement

Steve2718

New Member
Joined
Jun 4, 2009
Messages
22
Please can you advise me of a way to determine how I can check a list of documents for certain criteria.

Name Number Title

Joe Smith 12345 51
Joe Smith 12345 51A

Here I would get a correct or something as there is a 51 and 51 A for this record.

Joe Smith 125656 51
Jane Jones 224545 51A

Here I would get an error as there is only a 51 for Joe Smith

Finally if there are 2 51As or 2 51s for a person I need an error message.

I was thinking about IS Number.

Can you help.
Thanks
Steve
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I tend to dive into VBA with very little encouragement, and this struck me as more suited to a VBA solution than using worksheet functions.

How big do these lists tend to get?
 
Upvote 0
Try this:-
Code:
Option Explicit
 
Public Sub MatchReport()
 
  Dim ws As Worksheet
  Dim iLastRow As Long
  Dim arrStore As Variant
  
  Dim i As Long
  Dim j As Long
  
  Set ws = ThisWorkbook.Sheets("Sheet1")
  
  iLastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
  
  arrStore = ws.Range("A1:C" & CStr(iLastRow))
  For i = 2 To UBound(arrStore, 1) - 1
    For j = i + 1 To UBound(arrStore, 1)
      If arrStore(i, 1) <> "" And arrStore(i, 1) = arrStore(j, 1) And arrStore(i, 2) = arrStore(j, 2) Then
        Select Case arrStore(i, 3) & arrStore(j, 3)
          Case "5151A", "51A51"
            arrStore(i, 1) = "": arrStore(i, 2) = "": arrStore(i, 3) = ""
            arrStore(j, 1) = "": arrStore(j, 2) = "": arrStore(j, 3) = ""
        End Select
      End If
    Next j
  Next i
  
  For i = 2 To UBound(arrStore, 1)
    If arrStore(i, 1) = "" Then
      ws.Cells(i, 4) = "Ok"
    Else
      ws.Cells(i, 4) = "Error"
    End If
  Next i
  
End Sub
This assumes your worksheet is called Sheet1, your data is in columns A-C and column D is free to place a result code.

As always, test on a copy of your workbook.
 
Upvote 0
Thanks for this but can it be done without using Visual Basic.
Possibly, but it took me a few minutes to cobble together the VBA whereas it would have taken me much longer to produce a function-based solution.

I'm sure someone will come up with a non-VBA solution before too long.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,875
Members
452,949
Latest member
Dupuhini

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