Complex Formula Value Distribute

aqeelnokia99

Board Regular
Joined
Dec 23, 2018
Messages
145
Office Version
  1. 2013
Platform
  1. Windows
Hi Experts i try to Distribute Value from Table 1 Until its Reached Value 1000000 if its Reached Write Remaining amount and start from again from Remain amount for Example
if you see Result from Value 1130 to 465001 Total is 979026 to Reach @ 1000000 we need more 1000000-979026 =20974 This amount will come from Table 1 SR # 5 Which is 250000 After That is you see Result Table next value is 229026 which = to 250000-20974 so on in Simple Distribute Value of table 1 Value Until its Reached 1000000 if its Possible with formula or Vba will Very Big Thanks

Table 11000000
SR#EurosResult
111301130
2171361171361
3341534341534
4465001465001
525000020974This Part is Remaing Balance to Reach amount 1000000
6390854229026Start from again from 250000-20974
7307572390854
8710127307572
960000072548
10260208637579
11500000362421
12274438
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi @aqeelnokia99. Thanks for posting on the forum.


I show you a possible solution with VBA. (Help columns are not required)
Important. The values are read from cells C3 and up to the last row with values from column C, the result in cell G3 onwards. If you modify the source or destination cells, we need to adjust the macro.

VBA Code:
Sub Distribute_Value()
  Dim i As Long, k As Long
  Dim nTop As Double, nSum As Double
  Dim a As Variant, b As Variant
 
  nTop = 1000000
  a = Range("C3", Range("C" & Rows.Count).End(3)).Value
  ReDim b(1 To UBound(a, 1) * 3, 1 To 1)
 
  For i = 1 To UBound(a)
    nSum = nSum + a(i, 1)
    k = k + 1
    If nSum < nTop Then
      b(k, 1) = a(i, 1)
    ElseIf nSum = nTop Then
      b(k, 1) = a(i, 1)
      nSum = 0
    Else
      b(k, 1) = nTop - (nSum - a(i, 1))
      b(k + 1, 1) = a(i, 1) - b(k, 1)
      nSum = b(k + 1, 1)
      k = k + 1
    End If
  Next
  Range("G3").Resize(UBound(b, 1)).Value = b
End Sub

--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
Awesome Big Thanks
 
Upvote 1
Try the following :

Cell Formulas
RangeFormula
G3:G31G3=IF(G2>$D$1,B3,G2+B3)
H3H3=IF(G3>$D$1,IF($D$1*COUNTIF($G$3:G3,">"&$D$1)-SUM($D2:D$3)=0,B3,$D$1*COUNTIF($G$3:G3,">"&$D$1)-SUM($D2:D$3)),B3)
I3:I31I3=IF($D$1*COUNTIF($G$3:G3,">"&$D$1)-SUM($H$3:H3)=0,B3-H3,"")
J3:J31J3=IFERROR(INDEX(Data,1+INT((ROW(A1)-1)/COLUMNS(Data)),MOD(ROW(A1)-1+COLUMNS(Data),COLUMNS(Data))+1),"")
H4:H31H4=IF(G4>$D$1,IF($D$1*COUNTIF($G$3:G4,">"&$D$1)-SUM($H$3:H3)=0,B4,$D$1*COUNTIF($G$3:G4,">"&$D$1)-SUM($H$3:H3)),B4)
D3:D17D3=IFERROR(INDEX(J:J,SMALL(IF(J$3:J$1000<>"",ROW(J$3:J$1000)), ROWS(J$3:J3))), "")
 
Upvote 0
i found 1 issue after result 307572 Row #10 Next Result must 72548 because to Reach on 1000000 we need more 72548
10000001130
171361
341534
465001
20974
1000000229026
390854
307572
72548
1000000637579
362421
 
Upvote 0
Try the updated version :

Cell Formulas
RangeFormula
G3:G7G3=IF(G2>$D$1,B3,G2+B3)
H3H3=IF(G3>$D$1,IF($D$1*COUNTIF($G$3:G3,">"&$D$1)-SUM($H2:I$3)=0,B3,$D$1*COUNTIF($G$3:G3,">"&$D$1)-SUM($H2:I$3)),B3)
I3I3=IF($D$1*COUNTIF($G$3:G3,">"&$D$1)-SUM($H$3:H3)=0,B3-H3,"")
J3:J31J3=IFERROR(INDEX(Data,1+INT((ROW(A1)-1)/COLUMNS(Data)),MOD(ROW(A1)-1+COLUMNS(Data),COLUMNS(Data))+1),"")
H4:H31H4=IF(G4>$D$1,IF($D$1*COUNTIF($G$3:G4,">"&$D$1)-SUM($H$3:I3)=0,B4,$D$1*COUNTIF($G$3:G4,">"&$D$1)-SUM($H$3:I3)),B4)
I4:I31I4=IF($D$1*COUNTIF($G$3:G4,">"&$D$1)-SUM($H$3:H4)-SUM($I$3:I3)=0,B4-H4,"")
G8:G31G8=IF(G7>$D$1,B8+I7,G7+B8)
D3:D20D3=IFERROR(INDEX(J:J,SMALL(IF(J$3:J$1000<>"",ROW(J$3:J$1000)), ROWS(J$3:J3))), "")


Data refers to Named range = $H$3:$I$31
 
Upvote 0
i change Value its give negative Result for some reason
Apr-231000000
SR#DateEurosExchange RateBalance EurosResultHelper1Helper2Helper3Helper4
108-Nov-22200000224200000Apr-23200000200000200000
231-Jan-23171361288171361Apr-23371361171361
331-Jan-23341534288341534Apr-23712895341534171361
409-Feb-23465001290.111287105Apr-231177896287105177896
513-Feb-23250000280€ 229,026177896May-23250000250000341534
613-Feb-23390854288250000May-23640854390854
721-Feb-23307572279390854May-23948426307572287105
827-Feb-23710127274€ 637,579307572May-231658553-126322836449177896
909-Mar-23600000297.7€ 237,5791-126322May-231436449163551436449250000
1013-Mar-23260208302.2836449Jun-23696657260208
1121-Mar-235000003021163551Jun-231196657303343196657390854
1228-Mar-23274438304.81€ 272,225436449Jul-23471095274438
260208Jul-234710950307572
1303343Jul-234710950
196657Aug-234710950-126322
274438Aug-234710950836449
0Aug-234710950163551
0Aug-234710950436449
0Aug-234710950260208
#NUM!#NUM!#NUM!4710950
#NUM!#NUM!#NUM!4710950303343
#NUM!#NUM!#NUM!4710950196657
4710950274438
4710950
47109500
4710950
47109500
4710950
47109500
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,845
Members
449,471
Latest member
lachbee

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