Concatenate Column Title & Values until all the columns read, and write the data in to file as a one line

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>
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Apologize for the duplicated question. It wasn't intentional, while I was uploading the thread I got an error on key words. Unknowingly I kept on modifying and uploading the same thread. Later I realized the same thread had got duplicated. Hope the admin shall understand. Thank you in Advance.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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