Forum Discussion
Christian_Ecijan
Jan 16, 2024Copper Contributor
Excel formatting
Hi, I am trying to create a Macro for formatting some stuff but I'm not sure how to go about it. I want it to become like this. Please help
OliverScheurich
Jan 16, 2024Gold Contributor
Sub parts()
Dim i, j, k, m, n As Long
Range("F:XFD").Clear
k = Range("A" & Rows.Count).End(xlUp).Row
m = 2
For i = 2 To k
For j = 1 To Cells(i, 3).Value
Cells(m, 6).Value = Cells(i, 1).Value
Cells(m, 7).Value = Cells(i, 2).Value
If j = 1 Then
Cells(m, 8).Value = Cells(i, 3).Value
Else
End If
Cells(m, 9).Value = Left(Cells(i, 2).Value, 1) & j
If j = 1 And Cells(i, 3).Value > 1 Then
For n = 2 To Cells(i, 3).Value
Cells(m, n + 8).Value = Left(Cells(i, 2).Value, 1) & n
Next n
Else
End If
m = m + 1
Next j
Next i
End SubIn the attached file you can run the macro for the intended distribution of the data. However with a quantity of 16000 the result would be returned in columns H:WQR for this part number.
- Christian_EcijanJan 16, 2024Copper ContributorHi for this code, does it matter what Column I put the items?
I dont think I will go over 16000 for quantity so it should be okay.
Thanks- OliverScheurichJan 16, 2024Gold Contributor
You are welcome. The part number, description and quantity must be entered in columns A, B and C like in the sample file otherwise it wouldn't work. But of course the code can be adapted if required.