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

Status
Not open for further replies.

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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Duplicate https://www.mrexcel.com/forum/excel...ll-columns-read-write-data-file-one-line.html

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).

Note that sometimes posts from new users require Moderator approval before you can see them on the public forums. When this happens, you should see a message to that effect when you try to post it. Please be patient and do not attempt to post the question again.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,216,499
Messages
6,131,010
Members
449,613
Latest member
MedDash99

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