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./.

ABCDEFGHIJ
(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)
xxxxR101100zzz
xxxxR102200zzzz
xxxxR103500yyyy
yyyyR10110xxxx
yyyyR1025.....
yyyyR10320
zzzzR1015000
zzzzR1026000
zzzzR1037000
..............

<tbody>
</tbody>
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
How about


Excel 2013 32 bit
ABCDEFGHIJ
2xxxxR101100zzz000
3xxxxR102200zzzz500060007000
4xxxxR103500yyyy10520
5yyyyR10110xxxx100200500
6yyyyR1025.....
7yyyyR10320
8zzzzR1015000
9zzzzR1026000
10zzzzR1037000
11..............
Sheet1
Cell Formulas
RangeFormula
H2=SUMPRODUCT(($A$2:$A$10=$G2)*($B$2:$B$10="R101"),$C$2:$C$10)
I2=SUMPRODUCT(($A$2:$A$10=$G2)*($B$2:$B$10="R102"),$C$2:$C$10)
J2=SUMPRODUCT(($A$2:$A$10=$G2)*($B$2:$B$10="R103"),$C$2:$C$10)
 
Last edited:
Upvote 0
Thanks @Fluff a lot

But my data obout 5.000 rows defen on each month, so file is bigger size. Could you help me do that by VBA code and clear range (H2:J) when run code?
 
Upvote 0
Do you have a header in A1:J1?
 
Upvote 0
How about
Code:
Sub LookupData()
   Dim rng As Range
   
   Set rng = Range("A2", Range("A" & Rows.Count).End(xlUp))
   With Range("H2", Range("H" & Rows.Count).End(xlUp))
      .FormulaR1C1 = "=SUMPRODUCT((" & rng.Address(, , xlR1C1) & "=rc[-1])*(" & rng.Offset(, 1).Address(, , xlR1C1) & "=""R101"")," & rng.Offset(, 2).Address(, , xlR1C1) & ")"
      .Offset(, 1).FormulaR1C1 = "=SUMPRODUCT((" & rng.Address(, , xlR1C1) & "=rc[-2])*(" & rng.Offset(, 1).Address(, , xlR1C1) & "=""R102"")," & rng.Offset(, 2).Address(, , xlR1C1) & ")"
      .Offset(, 2).FormulaR1C1 = "=SUMPRODUCT((" & rng.Address(, , xlR1C1) & "=rc[-3])*(" & rng.Offset(, 1).Address(, , xlR1C1) & "=""R103"")," & rng.Offset(, 2).Address(, , xlR1C1) & ")"
      .Resize(, 3).Value = .Resize(, 3).Value
   End With
End Sub
 
Upvote 0
Forgot to clear the range first
Code:
Sub LookupData()
   Dim rng As Range
   
   Set rng = Range("A2", Range("A" & Rows.Count).End(xlUp))
   With Range("H2", Range("H" & Rows.Count).End(xlUp))
      .Resize(, 3).ClearContents
      .FormulaR1C1 = "=SUMPRODUCT((" & rng.Address(, , xlR1C1) & "=rc[-1])*(" & rng.Offset(, 1).Address(, , xlR1C1) & "=""R101"")," & rng.Offset(, 2).Address(, , xlR1C1) & ")"
      .Offset(, 1).FormulaR1C1 = "=SUMPRODUCT((" & rng.Address(, , xlR1C1) & "=rc[-2])*(" & rng.Offset(, 1).Address(, , xlR1C1) & "=""R102"")," & rng.Offset(, 2).Address(, , xlR1C1) & ")"
      .Offset(, 2).FormulaR1C1 = "=SUMPRODUCT((" & rng.Address(, , xlR1C1) & "=rc[-3])*(" & rng.Offset(, 1).Address(, , xlR1C1) & "=""R103"")," & rng.Offset(, 2).Address(, , xlR1C1) & ")"
      .Resize(, 3).Value = .Resize(, 3).Value
   End With
End Sub
 
Upvote 0
In that case make this change
Code:
With Range("H2", Range("G" & Rows.Count).End(xlUp).Offset(,1))
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,209
Members
448,874
Latest member
b1step2far

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