VBA Code for creating a formula for adding specific values (=IF(A2:A10)=B2,B2,C2))

Feroz90

Board Regular
Joined
Apr 25, 2019
Messages
52
Hi All,

In the below example, I want to add each days splitted amount in Amt 3 and reconcile with Amt 1 & Amt 2, say for example, For Monday, if we add first 4 rows in Amt 3, we get 2000 which is in Amt 2 and if we add next 3 rows of Monday , we get 1000 which is in Amt 1. Anyone's help with any VBA code will be appreciated.

DaysAmt 1Amt 2Amt 3TotalExample
Monday100020005002000500 + 500 + 500 + 500
Monday100020005002000500 + 500 + 500 + 500
Monday100020005002000500 + 500 + 500 + 500
Monday100020005002000500 + 500 + 500 + 500
Monday100020002501000500 + 250 + 250
Monday100020002501000500 + 250 + 250
Monday100020005001000500 + 250 + 250
Tuesday290011007502900750 + 750 + 500 + 450 +450
Tuesday290011007502900750 + 750 + 500 + 450 +450
Tuesday290011006001100600 + 500
Tuesday290011005001100600 + 500
Tuesday290011005002900750 + 750 + 500 + 450 +450
Tuesday290011004502900750 + 750 + 500 + 450 +450
Tuesday290011004502900750 + 750 + 500 + 450 +450
Wednesday150025007501500750 + 750
Wednesday150025007501500750 + 750
Wednesday15002500100025001000 + 1000 + 250 +250
Wednesday15002500100025001000 + 1000 + 250 +250
Wednesday1500250025025001000 + 1000 + 250 +250
Wednesday1500250025025001000 + 1000 + 250 +250
Thursday22502750100022501000 + 250 +1000
Thursday225027507502750750 + 2000
Thursday2250275025022501000 + 250 +1000
Thursday2250275020002750750 + 2000
Thursday22502750100022501000 + 250 +1000
Friday845015504508450450 + 2000 + 3000 + 1000 + 2000
Friday845015505501550550 + 1000
Friday8450155020008450450 + 2000 + 3000 + 1000 + 2000
Friday8450155030008450450 + 2000 + 3000 + 1000 + 2000
Friday8450155010001550550 + 1000
Friday8450155010008450450 + 2000 + 3000 + 1000 + 2000
Friday8450155020008450450 + 2000 + 3000 + 1000 + 2000

<colgroup><col><col span="4"><col></colgroup><tbody>
</tbody>

Thanks you in advance
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi All,

All I need is to get a formula of =IF(A2:A10)=B2,B2,C2) Lets say, A2:A10 have 100 each and in B2 I have 500, so if the use this formula i need to get 500 or else anything in C2. Appreciate for helping me.

I use this code to finding specific value in the list, can any one give me an idea or vba code for the below.

Function GetCombination(CoinsRange As Range, SumCellId As Double) As String
'updateby Extendoffice 20160506
Dim xStr As String
Dim xSum As Double
Dim xCell As Range
xSum = SumCellId
For Each xCell In CoinsRange
If Not (xSum / xCell < 1) Then
xStr = xStr & "1 of " & xCell & " "
' xSum = xSum - xCell
End If
Next
GetCombination = xStr
End Function
 
Upvote 0
This is not a valid formula:
Code:
[COLOR=#333333]=IF(A2:A10)=B2[/COLOR]
Checking for a whole range of values equal to one cell really does not make any sense.
What is it exactly you are trying to do?
Are you trying to see if the SUM of A2:A10 is equal to B2?
Or are you trying to see if every cell in A2:A10 is equal to B2?
 
Upvote 0
Hi,

I want it like, in the below table if you add 500 + 500 + 500 + 500, we get the C2, i.e 2000, the remaining amount will cover the B2, so i want to create a formula like, =IF(SUM(D2:D8)=C2,C2,B2), Where C2 = 2000, B2 = 1000. Thanks

Monday10002000500
Monday10002000500
Monday10002000500
Monday10002000500
Monday10002000500
Monday10002000250
Monday10002000250

<tbody>
</tbody>
 
Last edited:
Upvote 0
i want to create a formula like, =IF(SUM(D2:D8)=C2,C2,B2)
Didn't you just do that (create the formula)?

=IF(SUM(D2:D8)=C2,C2,B2)
is a valid formula.
What is the issue with it?

 
Last edited:
Upvote 0
Hi,

Please look at the example, if you Sum the Column 3, you will get 3000 and not 2000, all I need is to get only 2000, so i want to create a formula in this method.

=IF(SUM(D2:D8)=C2,C2,B2), Here, (D2:D8)=(500:500:500:500:500:250:250), C2 = 2000, B2 = 1000.

Thanks
 
Upvote 0
So, you want to know if adding up the values from the last column (D), equal the value in the first line of column (C)?
Is that right?
Do the values always have to be in order in column D?
The only way I know of doing something like that would be to use VBA.
Maybe someone knows of a way with some sort of array functions, but I do not.
 
Upvote 0
Hi Feroz90,

A guess but are you actually looking for C2 to contain the sum of D2:D8 up to a maximum of 2000, and if the sum of D2:D8 is greater than 2000 then B2 should contain the remainder?

If so:-
In C2 put =MIN(2000,SUM(D2:D8))
In B2 put =SUM(D2:D8)-C2

Note - Formulas in Excel only populate the cell they are in.

Hope this helps,

Eric.
 
Upvote 0
Thank you Eric, But i want to know which are all in the list matches with B2 & which are all matches with C2.
 
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

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