Hello,
[CASE 1]
I am working on a code to loop through my data, find through the worksheet based on 2 criterias and offset to the column on the right of the find result.
[CASE 2] -- If [CASE 1] is not a match
BUT if find isn't a match of both criterias... then look through second range.
This is what I have so far and its pretty far off from what I need.
Here is a sample of the data - In the highlighted row you will see expected result in column W
Here is example of data range to find in .. there is a second sheet similar to this which would be the second range to look through - highlighted in this sheet is the match that I need to offset and bring back to ws.range("W" & i).value =
I apologize if this isn't enough information and will be happy to provide more
TIA
EDIT := If there are multiple matches (in either case) the amounts would need to be added up
[CASE 1]
I am working on a code to loop through my data, find through the worksheet based on 2 criterias and offset to the column on the right of the find result.
[CASE 2] -- If [CASE 1] is not a match
BUT if find isn't a match of both criterias... then look through second range.
This is what I have so far and its pretty far off from what I need.
VBA Code:
Set Rng = Rws1.Range("F2:Z" & Rws1.Cells(Rows.Count, 3).End(xlUp).Row) 'Rws is [CASE1] Range
Set Rng2 = Rws2.Range("F2:Z" & Rws2.Cells(Rows.Count, 3).End(xlUp).Row) 'Rws is [CASE2] Range
For i = 2 To lastrow ' lastrow is last row of data
If ws.Cells(i, 22).Value = "TRUE" Then 'Boolean to activate find -- ignore for all intent and purposes
Else
Set Rng = Rws1.Range("F2:Z" & Rws1.Cells(Rows.Count, 3).End(xlUp).Row).Find(what:=ws.Range("F" & i), lookat:=xlWhole, LookIn:=xlValues)
Do While Not Rng Is Nothing
ws.Range("W" & i).Value = Rng.Offset(0, 1).Value ' at this point, code finds first match and gives me the value on the right of the found column -- Ignoring the criteria because I haven't worked that in...
Set Rng = rang.FindNext(after:=Rng)
Loop
End If
Next i
Here is a sample of the data - In the highlighted row you will see expected result in column W
Book1 | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | |||
1 | Payment input CSV output target | Sheet Name | Item Line No | Complement | Slip Number | Buyer Id | Seller Id | Payment | Payment Type Code | Payment Date | Payment Amount | Scheduled Payment | Scheduled Payment of Tax Excluded | Scheduled Other Payment | Apply Reason Code | Payment Remarks | Seller TOKUREI Status | Buyer TOKUREI Status | Canceled | Amount paid | Prefix Sign | Exact | Target | ||
2 | 24562 | 123 | 1 | 1 | 24700 | 24700 | 1300 | 24700 | M | TRUE | |||||||||||||||
3 | 6256 | 234 | 1 | 1 | 12350 | 12350 | 650 | 12350 | M | TRUE | |||||||||||||||
4 | 623456 | 234 | 1 | 1 | 12350 | 12350 | 650 | 12350 | M | TRUE | |||||||||||||||
5 | 23456 | 5125 | 1 | 1 | 12350 | 12350 | 650 | 12350 | M | TRUE | |||||||||||||||
6 | 23456 | 1254 | 1 | 1 | 12350 | 12350 | 650 | 12350 | M | TRUE | |||||||||||||||
7 | 136136 | 5 | 1 | 1 | 4400 | 5225 | 275 | 5225 | M | FALSE | 4987.5 | ||||||||||||||
8 | 2356 | 1617 | 1 | 1 | 12350 | 12350 | 650 | 13000 | M | TRUE | |||||||||||||||
9 | 346 | 77 | 1 | 1 | 12350 | 12350 | 650 | 12350 | M | TRUE | |||||||||||||||
10 | 346 | 123 | 1 | 3 | 10450 | 10450 | 550 | 10450 | M | TRUE | |||||||||||||||
Sheet1 |
Here is example of data range to find in .. there is a second sheet similar to this which would be the second range to look through - highlighted in this sheet is the match that I need to offset and bring back to ws.range("W" & i).value =
Book2 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | |||
1 | Note | Recovery Reason | Sale ID | Distributor ID | Total Recovery Amount | Recovery ID 1 | Recovered Amount 1 | Recovery ID 2 | Recovered Amount 2 | Recovery ID 3 | Recovered Amount 3 | Recovery ID 4 | Recovered Amount 4 | |||
2 | 123 | 1 | 6738 | 6136136 | 3420 | 13613 | 3318 | |||||||||
3 | 123 | 2 | 4987.5 | 1361361 | 4987.5 | |||||||||||
4 | 123 | 3 | 12350 | 136 | 12350 | |||||||||||
5 | 123 | 4 | 4987.5 | 13613 | 4987.5 | |||||||||||
6 | 123 | 5 | 4987.5 | 123 | 4987.5 | 13613 | 1235 | 136136 | 4987.5 | |||||||
7 | 345 | 6 | 4370 | 136136136 | 4370 | |||||||||||
8 | 345 | 7 | 19950 | 136 | 19950 | |||||||||||
9 | 345 | 8 | 5225 | 136136136 | 5225 | |||||||||||
10 | 345 | 9 | 9975 | 36136 | 9975 | |||||||||||
11 | 345 | 123 | 20212.5 | 36136 | 12512.5 | 36 | 7700 | |||||||||
12 | 345 | 16 | 8692.5 | 1361 | 4987.5 | 136 | 3705 | |||||||||
13 | 456 | 123 | 3420 | 36 | 3420 | |||||||||||
14 | 456 | 234 | 6840 | 36 | 6840 | |||||||||||
15 | 456 | 345 | 4987.5 | 36 | 1235 | 136 | 1235 | 13613 | 1235 | 1361 | 1282.5 | |||||
16 | 456 | 1512 | 2090 | 136 | 2090 | |||||||||||
17 | 456 | 4 | 2090 | 36 | 2090 | |||||||||||
Sheet1 |
I apologize if this isn't enough information and will be happy to provide more
TIA
EDIT := If there are multiple matches (in either case) the amounts would need to be added up
Last edited by a moderator: