converting output from columns and adding fields to existing row.

tinker11

New Member
Joined
Aug 14, 2019
Messages
8
I have a po file with three columns - part no, due date and qty due in column form. I need to change output to have the part number in column 1, then followed by first po due date, first po qty, second po due date second po qty. on attached file, top half is what my output looks like from a pivot table. (can be changed to vba if needed)..the highlighted green cells on the bottom half is what I need to produce.
I don't need to use a pivot, all help is really appreciated.
 

Attachments

  • excelhelp.PNG
    excelhelp.PNG
    27.7 KB · Views: 14

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
what about?
converting output from columns and adding fields to existing row.xlsx
ABCDEFGHIJKLMNOPQRST
1Part No.Due date# PO Qty Open
2989202/03/20214500
3989202/19/2021360
4989202/19/20213000
5989202/21/20217020
6989203/01/20214620
7989204/01/202110020
8989204/22/20212040
9989210/01/20215280
106809603/01/2021800
116809603/01/20211000
126809603/01/20212500
136809604/01/20212500
146809604/22/2021800
156809604/22/2021100
16
17
18
19Part No.1st PO Date1st PO Qty2nd PO Date2nd PO Qty3rd PO Date3rd PO Qty4th PO Date4th PO Qty5th PO Date5th PO Qty6th PO Date6th PO Qty7th PO Date7th PO Qty8th PO Date8th PO Qty
20989202/03/2021450002/19/202136002/19/2021300002/21/2021702003/01/2021462004/01/20211002004/22/2021204010/01/20215280   
216809603/01/202180003/01/2021100003/01/2021250004/01/2021250004/22/202180004/22/2021100       
22
ورقة1
Cell Formulas
RangeFormula
A20:A21A20=IFERROR(INDEX($A$2:$A$15,AGGREGATE(15,6,((ROW($A$2:$A$15)-ROW($A$2)+1)/(--(MATCH($A$2:$A$15,$A$2:$A$15,0)=(ROW($A$2:$A$15)-ROW($A$2)+1)))),COUNTA($A$19:A19)+0)),"")
B20:B21,T20:T21,R20:R21,P20:P21,N20:N21,L20:L21,J20:J21,H20:H21,F20:F21,D20:D21B20=IF(CEILING(COLUMNS($B$20:B20),2)/2<=COUNTIF($A$2:$A$15,$A20),TEXT(INDEX($B$2:$B$15,AGGREGATE(15,6,(ROW($A$2:$A$15)-ROW($A$2)+1)/($A$2:$A$15=$A20),1)-1+MOD((CEILING(COLUMNS($B$20:B20),2)/2)-1,COUNTIF($A$2:$A$15,$A20))+1),"mm/dd/yyyy"),"")
C20:C21,S20:S21,Q20:Q21,O20:O21,M20:M21,K20:K21,I20:I21,G20:G21,E20:E21C20=IF(CEILING(COLUMNS($B$20:B20),2)/2<=COUNTIF($A$2:$A$15,$A20),INDEX($C$2:$C$15,AGGREGATE(15,6,(ROW($A$2:$A$15)-ROW($A$2)+1)/($A$2:$A$15=$A20),1)-1+MOD((CEILING(COLUMNS($B$20:C20),2)/2)-1,COUNTIF($A$2:$A$15,$A20))+1),"")



converting output from columns and adding fields to existing row.gif
 
Last edited:
Upvote 0
i will try this. so their could be hundreds of line items in the input file - would I copy this a20 out to final records. or could this be modified to read all inputs and proceed with formula?
my input file current has 1809 line items...changes daily.
 
Upvote 0
Please go through Mr: Fluff VBA Way I think it the bet way for Huge date
 
Upvote 0
Try This

VBA Code:
Sub Test()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long, nc As Long
  
   Ary = Sheets("Sheet1").Range("A1").CurrentRegion.Value2' ' Name sheet as you want  and range
   ReDim Nary(1 To 3, 1 To UBound(Ary) * UBound(Ary, 2))
   On Error Resume Next
    rn = 0
   For r = 2 To UBound(Ary)
      For c = 1 To 3
    
         If Ary(r, c) <> "" Then
        
            If c = 1 And InStr(1, Nary(nr, 1), Ary(r, 1), vbTextCompare) = 0 Then
             nr = nr + 1
            Nary(nr, 1) = Ary(r, 1)
            nc = 0
            If nr > 1 Then rn = rn + 1 'Reest Row starting Num 'newline
            
            ElseIf c > 1 Then
           If c = 2 Then
           nc = nc + 1
           Nary(rn + c - 1, nc + 1) = Application.Text(CDbl(Ary(r, c)), "mm/dd/yyy")
          
           Else
            nc = nc + 1
           Nary(rn + c - 2, nc + 1) = Ary(r, c)
          
            End If
            If nc > MaxNC Then MaxNC = nc
            
            End If
         End If
      Next c
   Next r
 
   Sheets("sheet4").Cells.Clear
   Sheets("sheet2").Range("A2").Resize(nr, MaxNC).Value = Nary' ' Name the sheet as you want and range
End Sub

Book1
ABC
1Part No.Due date# PO Qty Open
298922/3/20214500
398922/19/2021360
498922/19/20213000
598922/21/20217020
698923/1/20214620
798924/1/202110020
898924/22/20212040
9989210/1/20215280
10680963/1/2021800
11680963/1/20211000
12680963/1/20212500
13680964/1/20212500
14680964/22/2021800
15680964/22/2021100
16680974/22/2021200
17680974/22/2021300
18680974/22/2021400
19680974/22/2021500
20680974/22/2021600
21680974/22/2021700
22680974/22/2021800
23680974/22/2021900
24680974/22/20211000
25680974/22/20211100
26680974/22/20211200
27680974/22/20211300
28680974/22/20211400
Sheet3


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAA
1
298922/3/202145002/19/20213602/19/202130002/21/202170203/1/202146204/1/2021100204/22/2021204010/1/20215280
3680963/1/20218003/1/202110003/1/202125004/1/202125004/22/20218004/22/2021100
4680974/22/20212004/22/20213004/22/20214004/22/20215004/22/20216004/22/20217004/22/20218004/22/20219004/22/202110004/22/202111004/22/202112004/22/202113004/22/2021
5
Sheet4
 
Upvote 0
try this
VBA Code:
Sub converting_output_from_columns_and_adding_fields_to_existing_row()

  
   Dim Rng As Range
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long, nc As Long
   Dim CV As String, PV As String
   Set Rng = Sheets("Sheet1").Range("A1").CurrentRegion
   Ary = Rng.Value2
   ReDim Nary(1 To 10, 1 To UBound(Ary) * UBound(Ary, 2))
   nr = 2
    nc = 1
   For r = 2 To UBound(Ary)
      For c = 1 To 3
        CV = Ary(r, c) 'Get Current Value
        If c = 1 And PV <> "" And PV <> CV Then nr = nr + 1: nc = 1 'Update rows "nr": Reset Columns
            nc = nc + 1 ' Update Columns
            Nary(nr, nc) = CV
        If c = 1 Then nc = nc - 1: PV = CV  'Get previous Value
        If nc > Maxc Then Maxc = nc ' Get Maxumum nc range
      Next c
   Next r
   '''''''''''''''''''''''''''''''''''''' Basic ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   'Sheets("sheet1").Range("A20").Resize(nr, Maxc).Value = Nary

   '''''''''''''''''''''''''''''''''''''' Advance ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Nary(1, 1) = Ary(1, 1): Nary(1, 2) = "1st PO" & Chr(10) & "Date": Nary(1, 3) = "1st PO" & Chr(10) & "Qty"
    With Sheets("sheet1")
        With .Range("A20")
        .Resize(nr, Maxc).Value = Nary ' Create New Horizintal Tble
        .Resize(1, 3).Interior.Color = Rng.Cells(1, 1).Interior.Color ' Header Color
        .Offset(0, 1).Resize(1, 2).AutoFill Destination:=.Offset(0, 1).Resize(1, Maxc) ' Fill out Header
        .CurrentRegion.Borders.LineStyle = 1 'New Tbl Borders
        End With
    End With
End Sub
or
VBA Code:
Sub converting_output_from_columns_and_adding_fields_to_existing_row()

   Dim Rng As Range
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long, nc As Long
   Dim CV As String, PV As String
   Set Rng = Sheets("Sheet1").Range("A1").CurrentRegion
   Ary = Rng.Value2
   ReDim Nary(1 To 10, 1 To UBound(Ary) * UBound(Ary, 2))
   nr = 2
    nc = 1
   For r = 2 To UBound(Ary)
      For c = 1 To 3
        CV = Ary(r, c) 'Get Current Value
        If c = 1 And PV <> "" And PV <> CV Then nr = nr + 1: nc = 1 'Update rows "nr": Reset Columns
            nc = nc + 1 ' Update Columns
            Nary(nr, nc) = CV
        If c = 1 Then nc = nc - 1: PV = CV  'Get previous Value
        If nc > Maxc Then Maxc = nc ' Get Maxumum nc range
      Next c
   Next r
   Sheets("sheet1").Range("A20").Resize(nr, Maxc).Value = Nary


End Sub
Book1
DEFGHIJKLMNOPQRSTUVWXY
202nd PO Date2nd PO Qty3rd PO Date3rd PO Qty4th PO Date4th PO Qty5th PO Date5th PO Qty6th PO Date6th PO Qty7th PO Date7th PO Qty8th PO Date8th PO Qty9th PO Date9th PO Qty10th PO Date10th PO Qty11th PO Date11th PO Qty12th PO Date12th PO Qty
219892442463609892442463000989244248702098924425646209892442871002098924430820409892444705280
2268096442561000680964425625006809644287250068096443088006809644308100
Sheet1
 
Last edited:
Upvote 0
sorry missing Line "Nary(nr, 1) = CV"
Code:
            Nary(nr, nc) = CV
            Nary(nr, 1) = CV
        If c = 1 Then nc = nc - 1: PV = CV  'Get previous Value
Picture2.gif
 
Upvote 0
still getting runtime error 9 subscript out of range error
CV = Ary(r, c) 'Get Current Value
If c = 1 And PV <> "" And PV <> CV Then nr = nr + 1: nc = 1 'Update rows "nr": Reset Columns
nc = nc + 1 ' Update Columns
Nary(nr, nc) = CV
Nary(nr, 1) = CV
If c = 1 Then nc = nc - 1: PV = CV 'Get previous Value
If nc > Maxc Then Maxc = nc ' Get Maxumum nc range
Next c
Next r
Sheets("sheet1").Range("A20").Resize(nr, Maxc).Value = Nary
 
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,548
Members
449,038
Latest member
Guest1337

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