Copy Column data from Column J to column A

Hi anyone can help me on copying a data from column “J” to Column “A” and need to Delete the header Name (Refer to image 2?)

Do i need to use Copy/Paste range activity?


1 Like

Hi,

Copy/Paste range is one of solutions. Can you try as the following?

Regards,

Hi @vignesh.maruthappan

Input:

Macros Code:

Sub CopyColumnJtoColumnA()
    Dim ws As Worksheet
    Dim lastRow As Long
    
    ' Specify the worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
    
    ' Find the last row in column J
    lastRow = ws.Cells(ws.Rows.Count, "J").End(xlUp).Row
    
    ' Copy the data from column J to column A
    ws.Range("J2:J" & lastRow).Copy
    ws.Range("A2").PasteSpecial Paste:=xlPasteValues
    
    ' Clear the value in cell A1
    ws.Range("A1").ClearContents
End Sub

Text File:
Copy data from J to A.txt (522 Bytes)

Workflow:

Output:

Regards

1 Like

Hi @vignesh.maruthappan

Follow these steps:

  1. Read the Excel file using the “Read Range” activity to get the data into a DataTable.
  2. Iterate through each row of the DataTable.
  3. Copy the data from column “J” to column “A” for each row, excluding the header row.
  4. Delete the header name in column “A”.
  5. Write the modified DataTable back to the Excel file using the “Write Range” activity.

For example:

  1. Read Range (Excel file) → Output: dtExcel
  2. For Each Row (DataTable: dtExcel)
    Assign ->row(“A”) = row(“J”)
  3. Assign → dtExcel.Columns(“A”).ColumnName = “”
  4. Write Range (Excel file) → Input: dtExcel
1 Like


I am getting a declaration error.

Hi @vignesh.maruthappan

Please give the method name within double quotes "CopyColumnJtoColumnA"

Please refer the below workflow @vignesh.maruthappan
Main Sequence.xaml (12.4 KB)

Let me know if you face any difficulties.
Regards

1 Like

If exclude header Column J value sits in the header column of column A.(Attached image below)


image

HI,

Can you try Excel.Sheet("Sheet1").Range("A2") as the following?

Regards,

Thanks got it . One minor issue, I have not assigned any Header. name. It exports as Column1.


image

Hi @vignesh.maruthappan

Sorry that I shared you the wrong workflow:
Check this once. THis will meet your requirement

Main Sequence.xaml (10.7 KB)

Regards

1 Like

Do you mean if you read it as DataTable, Column1 is automatically added as the first column name?
If so, it’s specification of datatable (Datatable cannot have blank name column)

If you need to first column header as blank, can you try to read the table using ReadRange without AddHeader option, and write it using WriteRange etc without AddHeader option.

Regards,

1 Like

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