Copy Pasting Data from Excel template to CSV file wrong Output

Hi everyone,

I would appreciate the help for this issue I am facing.

Currently I want to copy the data from certain column in an Excel file. And bring it over to a CSV of a different template. I want to copy the data start from row 13,14,15,etc. and below as long as there is data.

If this info helps, Row 10 has unique column name to it.

The column I am interested are marked in green circle.

I wanna be able to populate this data to a csv file as below:
IMO to IMO. SHIPNAME to SHIPNAME etc.

What I have done is:

  1. I try reading the excel file from range “A13:V30” as falls in the range of the data I want:

  2. Read the CSV template:
    image

  3. I try assigning variable for each row:
    IMO = DT_file9_data.Rows(0)(0).ToString.Trim
    SHIPNAME = DT_file9_data.Rows(1)(0).ToString.Trim
    etc. as per below:

  4. I would add data row using Array Row:
    image

  5. And write the datatable to CSV:

image

But it gives this wrong Output instead:

I appreciate the help. Thank you in advance.

try assigning variable for each row:
IMO = DT_file9_data.Rows(0)(0).ToString.Trim
SHIPNAME = DT_file9_data.Rows(1)(0).ToString.Trim
etc. as per below:

DT_file9_data.Rows(1)(0).ToString.Trim This is accessing the first cell of the second row in the DataTable DT_file9_data. The 1 is the row index for the second row and 0 is the column index for the first column.

Your values will always be same since you have hardcoded the address.

Try with CurrentRow(0).Tostring.Trim So on and so forth the integer is the column index.

Like tankestest1 would be CurrentRow(1).tostring.trim since its the second column

Hi @muktadir

Thank you so much for your help! It works like a charm!

Below is the changes I did

I manage to get the data:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.