Hello, first time i would say Sorry if similar question is already posted by another users. I got text file which is i will retrieve to excel table structure. But i don't understand what is logic to solve this.i will appreciate for anyone that can help my issue.
Below is data from text file:
ORDMSGSUPPLIE R NAMEAIA IAIAIAIAI CV. PONUMBER12015100920151013CUSTOMERGROUP BLABLABLA BLABL 111111A010
ORDDTL11111111 0002500240026400010003086PRODUCTNAME111111111 0 0 7078500
ORDDTL22222222222220001300480065760020013772PRODUCTNAME222222222 0 0 9168588
ORDDTL33333333333330000600960032640020017057PRODUCTNAME333333333 0 0 2100384
ORDDTL44444444444440000800720037440020017974PRODUCTNAME444444444 0 0 3212352
ORDMSGSUPPLIE R NAMEAIA IAIAIAIAI CV. PONUMBER22015100920151013CUSTOMERGROUP BLABLABLA BLABL 111111A010
ORDDTL55555555555550001300480030720020017349PRODUCTNAME111111111 0 0 4283136
ORDDTL66666666666660002500240017280020042026PRODUCTNAME222222222 0 0 4633200
ORDMSGSUPPLIE R NAMEAIA IAIAIAIAI CV. PONUMBER32015100920151013CUSTOMERGROUP BLABLABLA BLABL 111111A010
ORDDTL55555555555550000302400105960010000665PRODUCTNAME111111111 0 0 3409263
ORDDTL33333333333330000600960092448010008588PRODUCTNAME222222222 0 0 5949028,8
ORDMSGSUPPLIE R NAMEAIA IAIAIAIAI CV. PONUMBER42015100920151013CUSTOMERGROUP BLABLABLA BLABL 111111A010
ORDDTL77777777777770002500240037920020008415PRODUCTNAME111111111 0 0 10167300
ORDDTL88888888888880002500240034680020008420PRODUCTNAME222222222 0 0 9298575
ORDMSGSUPPLIE R NAMEAIA IAIAIAIAI CV. PONUMBER52015100920151013CUSTOMERGROUP BLABLABLA BLABL 111111A010
ORDDTL99999999999990001300480069120010026930PRODUCTNAME111111111 0 0 9637056
i have tried as far as i understand with vba code but it's only worked for 1 PO number. Here is the result:
NO_PO TGL_PO EXPRD Barcode QTY Store_Code
PONUMBER1 20151009 20151013 11111111 25 1A010
PONUMBER1 20151009 20151013 2222222222222 13 1A010
PONUMBER1 20151009 20151013 3333333333333 6 1A010
PONUMBER1 20151009 20151013 4444444444444 8 1A010
Here is the VBA code
'-----------------------------------------------------------------
Sub readTextFile()
Dim No_PO As String
Dim TGL_PO As String
Dim EXPRD As String
Dim BARCODE As String
Dim QTY As String
Dim STR_CODE As String
Dim f_text2 As String
f_text2 = ActiveWorkbook.Name
Workbooks(f_text2).Activate
Worksheets("raw_csv").Select
ClearData
Range("A2").Activate
Dim MyFolder As String
Dim txtfile2 As String
Dim folderName As String
txtfile2 = "order_data.txt"
folderName = "C:\local_data\raw_data\"
Workbooks.OpenText Filename:=folderName & "\" & txtfile2
Workbooks(txtfile2).Activate
Range("A1").Activate
No_PO = ActiveCell.Offset(0, 0).Value
TGL_PO = ActiveCell.Offset(0, 0).Value
RDD = ActiveCell.Offset(0, 0).Value
STR_CODE = ActiveCell.Offset(0, 3).Value
Do Until ActiveCell.Offset(1, 3).Value <> ""
ActiveCell.Offset(1, 0).Activate
BARCODE = ActiveCell.Offset(0, 0).Value
QTY = ActiveCell.Offset(0, 0).Value
'Personal_Responsibility = ActiveCell.Offset(51, 0).Value
'Position = ActiveCell.Offset(53, 0).Value
'ActiveCell.Offset(60, 0).Activate 41
Workbooks(f_text2).Activate
Worksheets("raw_csv").Select
ActiveCell.Value = Mid(Trim(No_PO), 41, 10)
ActiveCell.Offset(0, 1).Value = Mid(Trim(TGL_PO), 51, 8)
ActiveCell.Offset(0, 2).Value = Mid(Trim(EXPRD), 59, 8)
ActiveCell.Offset(0, 3).Value = Mid(Trim(BARCODE), 7, 13)
ActiveCell.Offset(0, 4).Value = Mid(Trim(QTY), 20, 5)
ActiveCell.Offset(0, 5).Value = Mid(Trim(STR_CODE), 6, 6)
ActiveCell.Offset(1, 0).Activate
Workbooks(txtfile2).Activate
Loop
End Sub
'----------------------------------------------------------------
i want to expect result in excel table like below:
NO_PO TGL_PO EXPRD Barcode QTY Store_Code
PONUMBER1 20151009 20151013 11111111 25 1A010
PONUMBER1 20151009 20151013 2222222222222 13 1A010
PONUMBER1 20151009 20151013 3333333333333 6 1A010
PONUMBER1 20151009 20151013 4444444444444 8 1A010
PONUMBER2 20151009 20151013 5555555555555 13 1A010
PONUMBER2 20151009 20151013 6666666666666 25 1A010
PONUMBER3 20151009 20151013 5555555555555 3 1A010
PONUMBER3 20151009 20151013 3333333333333 6 1A010
PONUMBER4 20151009 20151013 7777777777777 25 1A010
PONUMBER4 20151009 20151013 8888888888888 25 1A010
PONUMBER5 20151009 20151013 9999999999999 13 1A010
Below is data from text file:
ORDMSGSUPPLIE R NAMEAIA IAIAIAIAI CV. PONUMBER12015100920151013CUSTOMERGROUP BLABLABLA BLABL 111111A010
ORDDTL11111111 0002500240026400010003086PRODUCTNAME111111111 0 0 7078500
ORDDTL22222222222220001300480065760020013772PRODUCTNAME222222222 0 0 9168588
ORDDTL33333333333330000600960032640020017057PRODUCTNAME333333333 0 0 2100384
ORDDTL44444444444440000800720037440020017974PRODUCTNAME444444444 0 0 3212352
ORDMSGSUPPLIE R NAMEAIA IAIAIAIAI CV. PONUMBER22015100920151013CUSTOMERGROUP BLABLABLA BLABL 111111A010
ORDDTL55555555555550001300480030720020017349PRODUCTNAME111111111 0 0 4283136
ORDDTL66666666666660002500240017280020042026PRODUCTNAME222222222 0 0 4633200
ORDMSGSUPPLIE R NAMEAIA IAIAIAIAI CV. PONUMBER32015100920151013CUSTOMERGROUP BLABLABLA BLABL 111111A010
ORDDTL55555555555550000302400105960010000665PRODUCTNAME111111111 0 0 3409263
ORDDTL33333333333330000600960092448010008588PRODUCTNAME222222222 0 0 5949028,8
ORDMSGSUPPLIE R NAMEAIA IAIAIAIAI CV. PONUMBER42015100920151013CUSTOMERGROUP BLABLABLA BLABL 111111A010
ORDDTL77777777777770002500240037920020008415PRODUCTNAME111111111 0 0 10167300
ORDDTL88888888888880002500240034680020008420PRODUCTNAME222222222 0 0 9298575
ORDMSGSUPPLIE R NAMEAIA IAIAIAIAI CV. PONUMBER52015100920151013CUSTOMERGROUP BLABLABLA BLABL 111111A010
ORDDTL99999999999990001300480069120010026930PRODUCTNAME111111111 0 0 9637056
i have tried as far as i understand with vba code but it's only worked for 1 PO number. Here is the result:
NO_PO TGL_PO EXPRD Barcode QTY Store_Code
PONUMBER1 20151009 20151013 11111111 25 1A010
PONUMBER1 20151009 20151013 2222222222222 13 1A010
PONUMBER1 20151009 20151013 3333333333333 6 1A010
PONUMBER1 20151009 20151013 4444444444444 8 1A010
Here is the VBA code
'-----------------------------------------------------------------
Sub readTextFile()
Dim No_PO As String
Dim TGL_PO As String
Dim EXPRD As String
Dim BARCODE As String
Dim QTY As String
Dim STR_CODE As String
Dim f_text2 As String
f_text2 = ActiveWorkbook.Name
Workbooks(f_text2).Activate
Worksheets("raw_csv").Select
ClearData
Range("A2").Activate
Dim MyFolder As String
Dim txtfile2 As String
Dim folderName As String
txtfile2 = "order_data.txt"
folderName = "C:\local_data\raw_data\"
Workbooks.OpenText Filename:=folderName & "\" & txtfile2
Workbooks(txtfile2).Activate
Range("A1").Activate
No_PO = ActiveCell.Offset(0, 0).Value
TGL_PO = ActiveCell.Offset(0, 0).Value
RDD = ActiveCell.Offset(0, 0).Value
STR_CODE = ActiveCell.Offset(0, 3).Value
Do Until ActiveCell.Offset(1, 3).Value <> ""
ActiveCell.Offset(1, 0).Activate
BARCODE = ActiveCell.Offset(0, 0).Value
QTY = ActiveCell.Offset(0, 0).Value
'Personal_Responsibility = ActiveCell.Offset(51, 0).Value
'Position = ActiveCell.Offset(53, 0).Value
'ActiveCell.Offset(60, 0).Activate 41
Workbooks(f_text2).Activate
Worksheets("raw_csv").Select
ActiveCell.Value = Mid(Trim(No_PO), 41, 10)
ActiveCell.Offset(0, 1).Value = Mid(Trim(TGL_PO), 51, 8)
ActiveCell.Offset(0, 2).Value = Mid(Trim(EXPRD), 59, 8)
ActiveCell.Offset(0, 3).Value = Mid(Trim(BARCODE), 7, 13)
ActiveCell.Offset(0, 4).Value = Mid(Trim(QTY), 20, 5)
ActiveCell.Offset(0, 5).Value = Mid(Trim(STR_CODE), 6, 6)
ActiveCell.Offset(1, 0).Activate
Workbooks(txtfile2).Activate
Loop
End Sub
'----------------------------------------------------------------
i want to expect result in excel table like below:
NO_PO TGL_PO EXPRD Barcode QTY Store_Code
PONUMBER1 20151009 20151013 11111111 25 1A010
PONUMBER1 20151009 20151013 2222222222222 13 1A010
PONUMBER1 20151009 20151013 3333333333333 6 1A010
PONUMBER1 20151009 20151013 4444444444444 8 1A010
PONUMBER2 20151009 20151013 5555555555555 13 1A010
PONUMBER2 20151009 20151013 6666666666666 25 1A010
PONUMBER3 20151009 20151013 5555555555555 3 1A010
PONUMBER3 20151009 20151013 3333333333333 6 1A010
PONUMBER4 20151009 20151013 7777777777777 25 1A010
PONUMBER4 20151009 20151013 8888888888888 25 1A010
PONUMBER5 20151009 20151013 9999999999999 13 1A010
Last edited: