Forum Discussion
Alex_Barbosa99
Apr 30, 2023Copper Contributor
How to divide cell value in many lines?
Hello, I would like to create a macro to divide cell value in many lines as the following: Input: A 360 B 120 C 240 D 480 E 60 Output: A 120 A 120 A 1...
OliverScheurich
May 01, 2023Gold Contributor
Sub expand()
Dim h, i, j, k, l, m, n As Long
Range("D:E").Clear
m = 1
h = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To h
j = Cells(i, 2).Value / Range("I1").Value
k = Application.WorksheetFunction.RoundUp(j, 0)
For l = 1 To k
Cells(m, 4).Value = Cells(i, 1).Value
If Cells(i, 2).Value - n > Range("I1").Value Then
Cells(m, 5).Value = Cells(i, 2).Value / j
Else
Cells(m, 5).Value = Cells(i, 2).Value - n
End If
n = n + Range("I1").Value
m = m + 1
Next l
n = 0
Next i
End SubYou can try these lines of code. In the attached file you can click the button in cell H2 to run the macro. The divisor is entered in cell I2 which is 120 in this example.