How to split cell based on value with Macro and without Macro

scorpio3st

New Member
Joined
Sep 7, 2021
Messages
22
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Example:

I have:



2​
500​
8​
200​
5​
300​
2​
300​
1​
300​
5​
300​
2​
300​
5​
300​
2​
300​

In column A1 is number "2" and in column B1 is "500". I need to do 500/2 and show result in column-multiple rows, C1=250 and C2=250

if I have 500/8 i need to show result in C1,C2,C3,C4,C5,C6,C7,C8.

2​
500​
250​
2​
500​
250​
8​
200​
25​
8​
200​
25​
8​
200​
25​
8​
200​
25​
8​
200​
25​
8​
200​
25​
8​
200​
25​
8​
200​
25​

Thanks in advance.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Here is a formula approach using a helper column (which could be moved &/or hidden)

scorpio3st.xlsm
ABCD
125001250
282003250
353001125
423001625
513001825
6 25
7 25
8 25
9 25
1025
1160
1260
1360
1460
1560
16150
17150
18300
19 
20 
Repeat Rows
Cell Formulas
RangeFormula
C2:C9C2=IF(A2="","",C1+A1)
D1:D20D1=IF(ROWS(D$1:D1)>MAX(C$1:C$100),"",LOOKUP(ROWS(D$1:D1),C$1:C$100,B$1:B$100)/LOOKUP(ROWS(D$1:D1),C$1:C$100,A$1:A$100))
 
Upvote 0
A vba approach

VBA Code:
Sub Rpt()
  Dim a As Variant, b As Variant
  Dim dVal As Double
  Dim i As Long, j As Long, k As Long
  
  With Range("A1", Range("B" & Rows.Count).End(xlUp))
    a = .Value
    ReDim b(1 To Application.Sum(.Columns(1)), 1 To 1)
    For i = 1 To UBound(a)
      dVal = a(i, 2) / a(i, 1)
      For j = 1 To a(i, 1)
        k = k + 1: b(k, 1) = dVal
      Next j
    Next i
    .Offset(, 2).Resize(k, 1).Value = b
  End With
End Sub

scorpio3st.xlsm
ABC
12500250
28200250
3530025
4230025
5130025
625
725
825
925
1025
1160
1260
1360
1460
1560
16150
17150
18300
19
Repeat Rows (2)
 
Upvote 0
Solution
You're welcome. Thanks for the confirmation. :)
 
Upvote 0

Forum statistics

Threads
1,215,676
Messages
6,126,171
Members
449,296
Latest member
tinneytwin

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