sreeinkorea
New Member
- Joined
- Sep 15, 2017
- Messages
- 7
Dear All,
I've been trying to write a excel macro (VBA) as below.
My input : Excel sheet with multiple columns, and multiple rows
Expected Output: Read from 2nd row, until reaches the end of the columns, and then write the read input to the file (.bat file)
I need to read column title and respective row value, and create one liner as below,
im createissue --user=mac --password=mac.123 --port=7001 --field="<columna title="">=<columna(rowa) value="">" --field="<columnb title="">=<columnb(rowb) value="">" --field="<columnc title="">=<columnc(rowc) value="">" ..... and so on till i read end of column for One row.
The same shall repeat till the end of row, and create one line for each row as read above.
But my current output is producing the value as below after completing one row,
--field="<columna title="">=<columna(rowa) value="">"
--field="<columnb title="">=<columnb(rowb) value="">"
--field="<columnc title="">=<columnc(rowc) value="">"
im createissue --user=mac --password=mac.123 --port=7001 --field="<columnc title="">=<columnc(rowc) value="">"
Kind request if someone can spare some time to fix the issue. I need to put the column field values in to one row with prefix --field="" for each row.
Appreciate your help and support.
Thanking you.
Sincerely,
Sree
My piece of code
===============================================================
Sub upload_to_PTC_N_th_column()
Dim folderPath As String
Dim myFile As String
Dim cellValue As String
Dim i As Integer
Dim NumberRows As Integer
Dim issueID As String
Dim concatValue As String
folderPath = Application.ActiveWorkbook.Path
myFile = folderPath & "\Opl_issueList_uploadToPTC.bat"
Open myFile For Output As #1
NumberRows = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
'~~> Define variables
Set Rng = Range("C1:AZ10")
iRow = Rng(Rng.Rows.Count, 1).Row
iCol = 1
iMaxCol = Rng.Columns.Count
'start 2nd row to last row
For i = 2 To NumberRows
For iCol = 1 To iMaxCol
If Cells(i, iCol) <> "" Then
cellValue = " --field=" & Chr(34) & Cells(1, iCol) & "=" & Cells(i, iCol).Value & Chr(250) & """"
concatValue = cellValue
End If
If Not Cells(i, iCol) = "" Then
Print #1 , concatValue
End If
'cellValue = ""
Next iCol
If cellValue <> "" Then
Print #1 , "im createissue --user=mac --password=mac.123 --port=7001 " & concatValue
'Print #1 , cellValue
concatValue = ""
End If
cellValue = ""
Next i
Print #1 , "pause"
End Sub
===============================================================</columnc(rowc)></columnc></columnc(rowc)></columnc></columnb(rowb)></columnb></columna(rowa)></columna></columnc(rowc)></columnc></columnb(rowb)></columnb></columna(rowa)></columna>
I've been trying to write a excel macro (VBA) as below.
My input : Excel sheet with multiple columns, and multiple rows
Expected Output: Read from 2nd row, until reaches the end of the columns, and then write the read input to the file (.bat file)
I need to read column title and respective row value, and create one liner as below,
im createissue --user=mac --password=mac.123 --port=7001 --field="<columna title="">=<columna(rowa) value="">" --field="<columnb title="">=<columnb(rowb) value="">" --field="<columnc title="">=<columnc(rowc) value="">" ..... and so on till i read end of column for One row.
The same shall repeat till the end of row, and create one line for each row as read above.
But my current output is producing the value as below after completing one row,
--field="<columna title="">=<columna(rowa) value="">"
--field="<columnb title="">=<columnb(rowb) value="">"
--field="<columnc title="">=<columnc(rowc) value="">"
im createissue --user=mac --password=mac.123 --port=7001 --field="<columnc title="">=<columnc(rowc) value="">"
Kind request if someone can spare some time to fix the issue. I need to put the column field values in to one row with prefix --field="" for each row.
Appreciate your help and support.
Thanking you.
Sincerely,
Sree
My piece of code
===============================================================
Sub upload_to_PTC_N_th_column()
Dim folderPath As String
Dim myFile As String
Dim cellValue As String
Dim i As Integer
Dim NumberRows As Integer
Dim issueID As String
Dim concatValue As String
folderPath = Application.ActiveWorkbook.Path
myFile = folderPath & "\Opl_issueList_uploadToPTC.bat"
Open myFile For Output As #1
NumberRows = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
'~~> Define variables
Set Rng = Range("C1:AZ10")
iRow = Rng(Rng.Rows.Count, 1).Row
iCol = 1
iMaxCol = Rng.Columns.Count
'start 2nd row to last row
For i = 2 To NumberRows
For iCol = 1 To iMaxCol
If Cells(i, iCol) <> "" Then
cellValue = " --field=" & Chr(34) & Cells(1, iCol) & "=" & Cells(i, iCol).Value & Chr(250) & """"
concatValue = cellValue
End If
If Not Cells(i, iCol) = "" Then
Print #1 , concatValue
End If
'cellValue = ""
Next iCol
If cellValue <> "" Then
Print #1 , "im createissue --user=mac --password=mac.123 --port=7001 " & concatValue
'Print #1 , cellValue
concatValue = ""
End If
cellValue = ""
Next i
Print #1 , "pause"
End Sub
===============================================================</columnc(rowc)></columnc></columnc(rowc)></columnc></columnb(rowb)></columnb></columna(rowa)></columna></columnc(rowc)></columnc></columnb(rowb)></columnb></columna(rowa)></columna>