Help to get Cell value with multiple conditions

nhnn1986

Board Regular
Joined
Oct 12, 2017
Messages
92
Hi all

I need help to take value of Cell that:
with j = 2 to lastrow
if Cell(J;G).value = Cell(A2:A).value and Cell(i;B).value = "R101" then copy value in Cell(i;C) to Hj
if Cell(J;G).value = Cell(A2:A).value and Cell(i;B).value = "R102" then copy value in Cell(i;C) to Ij
if Cell(J;G).value = Cell(A2:A).value and Cell(i;B).value = "R103" then copy value in Cell(i;C) to Jj

This mean I want after run code, the result is:
H2 = 0, I2 = 0, J2 = 0
H3 = 5000, I3 = 6000, J3 = 7000
H4 = 10, I4 = 5, J4 = 20
..........

thanks./.

[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[/TR]
[TR]
[TD](1)[/TD]
[TD](2)[/TD]
[TD](3)[/TD]
[TD](4)[/TD]
[TD](5)[/TD]
[TD](6)[/TD]
[TD](7)[/TD]
[TD](8)[/TD]
[TD](9)[/TD]
[TD](10)[/TD]
[/TR]
[TR]
[TD]xxxx[/TD]
[TD]R101[/TD]
[TD]100[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]zzz[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]xxxx[/TD]
[TD]R102[/TD]
[TD]200[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]zzzz[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]xxxx[/TD]
[TD]R103[/TD]
[TD]500[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]yyyy[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]yyyy[/TD]
[TD]R101[/TD]
[TD]10[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]xxxx[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]yyyy[/TD]
[TD]R102[/TD]
[TD]5[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD].....[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]yyyy[/TD]
[TD]R103[/TD]
[TD]20[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]zzzz[/TD]
[TD]R101[/TD]
[TD]5000[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]zzzz[/TD]
[TD]R102[/TD]
[TD]6000[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]zzzz[/TD]
[TD]R103[/TD]
[TD]7000[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD].....[/TD]
[TD].....[/TD]
[TD]....[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Cross posted http://www.vbaexpress.com/forum/sho...py-cell-value-with-two-conditions-by-VBA-code

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
Sorry i don't now This forum don't accept the question asked with another forum already
 
Upvote 0
We do not prohibit members from asking the same question elsewhere, we simply ask that you inform us by including a link to the other sites.

If your description on vbax is anything to go by, I'm not surprised that it's returning 0s as you have given a different description of what your data looks like.
Is the data you showed in post#1 accurate?
 
Upvote 0
We do not prohibit members from asking the same question elsewhere, we simply ask that you inform us by including a link to the other sites.

If your description on vbax is anything to go by, I'm not surprised that it's returning 0s as you have given a different description of what your data looks like.
Is the data you showed in post#1 accurate?
Yes, there's the same data.
I deleted column C,D before post in this forum because there's no meanning and value in column A too long so I rewrite to shorter as you see
 
Upvote 0
What about the R101 versus R-101?
 
Upvote 0
It may be "simpler" but if that is not what your data is like it wont work, we need accurate information in order to help.
try
Code:
Sub LookupData()
   Dim rng As Range
   
   Set rng = Range("A2", Range("A" & Rows.Count).End(xlUp))
   With Range("H2", Range("G" & Rows.Count).End(xlUp).Offset(, 1))
      .Resize(, 3).ClearContents
      .FormulaR1C1 = "=SUMPRODUCT((" & rng.Address(, , xlR1C1) & "=rc[-1])*(" & rng.Offset(, 1).Address(, , xlR1C1) & "=""R-101"")," & rng.Offset(, 2).Address(, , xlR1C1) & ")"
      .Offset(, 1).FormulaR1C1 = "=SUMPRODUCT((" & rng.Address(, , xlR1C1) & "=rc[-2])*(" & rng.Offset(, 1).Address(, , xlR1C1) & "=""R-102"")," & rng.Offset(, 2).Address(, , xlR1C1) & ")"
      .Offset(, 2).FormulaR1C1 = "=SUMPRODUCT((" & rng.Address(, , xlR1C1) & "=rc[-3])*(" & rng.Offset(, 1).Address(, , xlR1C1) & "=""R-103"")," & rng.Offset(, 2).Address(, , xlR1C1) & ")"
      .Resize(, 3).Value = .Resize(, 3).Value
   End With
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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