Get the combination from values in VBA

mehidy1437

Active Member
Joined
Nov 15, 2019
Messages
348
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
  2. Mobile
  3. Web
Hello guys

I have value in M5:U5

25101020181210519

Now i want to get the combination of value which sum will be 30
Some values may not have any combination, those values will go to the last row, value like 20 & 19

Like as below:
255
101010
1812
2019

Please help me to solve this.

Sorry my XL2BB is not working at this laptop. So I can't post the data with that.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Book1
ABCDEFGHIJKL
12510102018121051930
2Sum
30000181200030
40002000100030
50010200000030
60100200000030
701010000100030
8250000005030
9
Sheet2
Cell Formulas
RangeFormula
A3:I8A3=LET(a,MID(DEC2BIN(SEQUENCE(512,,0),9), SEQUENCE(1,9),1)*A1:I1,b, MMULT(a,SEQUENCE(9,,,0)), FILTER(a,b=K1))
K3:K8K3=BYROW(A3#,LAMBDA(x,SUM(x)))
Dynamic array formulas.
 
Upvote 0
This is totally wrong, I have specified the desired output.
Also I need the solution with vba.
 
Upvote 0
I'm stuck with this. Can anyone help me figure it out, please?
 
Upvote 0
mehidy Let's get the ball rolling. Now your problem has more questions than answers. But we have to start somewhere. This is just the beginning version. If you like what you see than we will continue.

VBA Code:
Sub Prog()

Dim amt1 As Integer
Dim row1 As Integer
Dim col1 As Integer
Dim colcnt As Integer
Dim colcnt2 As Integer

row1 = 2
col1 = 1
colcnt = 1
colcnt2 = Cells(1, 1).End(xlToRight).Column
col1 = colcnt2 + 2

Range("A1").Cut Destination:=Range("A2")

For i = 1 To 8

Cells(row1, 11) = "=sum(r[0]c[-10]:r[0]c[-2])"

For a = 1 To 8

If Cells(1, colcnt + 1) = "" Then
colcnt = Cells(1, colcnt + 1).End(xlToRight).Column
colcnt = colcnt - 1
End If
Cells(1, colcnt + 1).Select

amt1 = Cells(1, colcnt + 1) + Cells(row1, 11)

If amt1 <= Range("K1") Then

Cells(1, colcnt + 1).Cut Destination:=Cells(row1, colcnt + 1)
colcnt = colcnt + 1

If amt1 = 30 Then Exit For

Else

colcnt = colcnt + 1
If colcnt2 = colcnt Then Exit For

End If

Next a

colcnt = Cells(1, 1).End(xlToRight).Column
If colcnt = col1 Then Exit Sub

Cells(1, colcnt).Cut Destination:=Cells(row1 + 1, colcnt)
If colcnt2 = colcnt Or colcnt = col1 Then Exit Sub

row1 = row1 + 1

Next i

End Sub

23-07-21 work 1.xlsm
ABCDEFGHIJK
12510105181210111930
2
3
4
5
6
7
8
9
1025101020181210519
1125101051812101119
Data
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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