Match opposites

rdev

Active Member
Joined
Dec 3, 2007
Messages
273
Please let me know how we can match as per below

Meet Google Drive – One place for all your files

I am looking for a macro that will see E2 in in column N , test column D to read the opposite of E2
I have the following but not coming good

code

Sub relatedpartyelimination()

lastrow = Sheets("Comm").Cells(Rows.Count, 1).End(xlUp).Row
v = 3
MsgBox lastrow

For *** = 2 To lastrow
x = Cells(***, 1).Value
u = Cells(***, 4).Value
fr = Cells(***, 5).Value
Z = Cells(***, 6).Value

If u = "Purchase of Goods" Then
u1 = "Sales of Goods"
If u = "Purchase of Services" Then
u1 = "Sales of Services"
End If
If u = "Amount Receivables" Then
u1 = "Amount Payables"
End If
If u = "Balances Payables with FSCM" Then
u1 = "Balances Payables with FSCM"
End If
End If

ot = 3
Do While ot < lastrow

If Cells(ot, 5).Value = x And Cells(ot, 4) = u1 Then
Cells(***, 7).Value = Cells(ot, 6).Value
End If
ot = ot + 1
Loop


Next ***



End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
That link doesn't actually link to a shared file. Do you want to try again or post a sample and what you mean by "read the opposite" exactly?
 
Upvote 0
With your new dataset:


Excel 2010
ABCDEFG
1CompanyTransactionTransaction PartyAmountMatchCompanyCounter Amount
2AlpaPurchase of goodsSilicon340,000SiliconPurchase of goodsF2 should equal to cell D5 after the following is satified[silicon is found in column A, we have 'Sales of goods' , i.e the opposite of 'Purchase of goods', cells E5= Alpa.
3AlpaSales of goodsNaturo275,000NaturoSales of goods
4AlpaSales of servicesCinbata78,000Cinbata-
5SiliconSales of goodsAlpa340,000Alpha340,000
6TetraPurchase of servicesAlpa122,000Alpha-
7NaturoPurchase of goodsAlpa275,000Alpha275,000
Sheet1


Code:
Sub test()
Dim c As Range, d As Range
For Each c In Range("E2:E" & Range("A" & Rows.Count).End(xlUp).Row)
    Set d = Range("A:A").Find(c)
    If Not d Is Nothing Then
        If Left(d.Offset(, 1), 8) = "Purchase" Then c.Offset(, 1) = "Sales" & Mid(d.Offset(, 1), 9)
        If Left(d.Offset(, 1), 5) = "Sales" Then c.Offset(, 1) = "Purchase" & Mid(d.Offset(, 1), 6)
    End If
Next
End Sub
 
Last edited:
Upvote 0
Just an example of the result I am looking for :
I have to look for the value in cell E2 value in column A,
If found then subject to conditions E9=A2 and D9 is the opposite of D2 , then put the values in cell A9 and F9 in cells G2 and H2 respectively and cells G9 and H9 should have values A2 and F2
The macro should the take row A3 and do same procedure as above, if not found then 'no result to be inserted'
 
Upvote 0
So in the above example the result should not go into Column H, but Column G (the opposite matching value) and in Column H the value from Column F. Is this correct?

Code:
Sub test()
Dim c As Range, d As Range
For Each c In Range("E2:E" & Range("A" & Rows.Count).End(xlUp).Row)
    Set d = Range("A:A").Find(c)
    If Not d Is Nothing Then
        If Left(d.Offset(, 1), 8) = "Purchase" Then c.Offset(, 2) = "Sales" & Mid(d.Offset(, 1), 9)
        If Left(d.Offset(, 1), 5) = "Sales" Then c.Offset(, 2) = "Purchase" & Mid(d.Offset(, 1), 6)
        c.Offset(, 3) = c.Offset(, 1)
    Else
        c.Offset(, 2) = "No Result"
    End If
Next
End Sub
 
Last edited:
Upvote 0
No the data in Column E and F are results after running the routine. The macro will look for Silicon in column A and if found , a second condition from Column B is to be meant, the opposite value of cell B2 and a third condition in column C in row 5 equal to cell A2
 
Upvote 0
I have tried but I just don't seem to quite understand what you are trying to accomplish.
 
Upvote 0
Please see if this makes sense what I want to achieve. The data remains what i posted in before


Sub usingFind()
Dim ms As Worksheet
Dim lastrow As Long, i As Long
Dim myCell As Range
Set ms = Sheets("mathew")
lastrow = Range("A" & Rows.Count).End(xlUp).Row
x = 2
y = 3
With ms.Range("A1:A" & lastrow)
c = ms.Cells(x, y).Value
u = ms.Cells(x, y).Offset(0, -1).Value
If u = "Purchase of goods" Then u1 = "Sales of goods"
If u = "Sales of goods" Then u1 = "Purchase of goods"
Set myCell = .Find(c)
If Not myCell Is Nothing And myCell.Offset(0, 1).Value = u1 And _
myCell.Offset(0, 2).Value = c Then
Cells(x, 5).Value = c
Cells(x, 5).Value = myCell.Offset(0, 3).Value
myCell.Offset(0, 4).Value = Cells(x, 1).Value
myCell.Offset(0, 4).Value = Cells(x, 1).Value
End If
End With

Exit Sub
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,424
Members
448,961
Latest member
nzskater

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