Append columns from one sheet to other sheet at different column

Hi ,

i have excel , like below

I have to copy the highlighted data to other sheet at different location on other sheet which already contains data.( basically i have append data)

Column B need to appended on Column N ,
Column C need to be appended on Column Q,
Column D to Column F … like wise.

Can you suggest the best way to do it?

Ahtesham

HI @md.ahtesham,
could you please attach screenshot of other sheet and its columns ?

Thanks!

Here is my code which i’m using to copy the excel columns from one sheet to another using VB

Hope this helps you as reference. let me know if you need full code

  For c As Integer = 1 To MTUsedColumnsRange
        Dim str As String = Convert.ToChar(64 + c)
        'system.Windows.MessageBox.Show(CType(ws.Cells(4, c), Microsoft.Office.Interop.Excel.Range).Value.ToString)
        If CType(ws.Cells(4, c), Microsoft.Office.Interop.Excel.Range).Value.ToString = "Project" Then
            ws.Range(str + "4:" + str + (MTUsedRange - 1).ToString).Copy()
            newSheet.Activate()
            newSheet.Range("B1").PasteSpecial(Microsoft.Office.Interop.Excel.XlPasteType.xlPasteValues)
            ws.Activate()
        ElseIf CType(ws.Cells(4, c), Microsoft.Office.Interop.Excel.Range).Value.ToString = "Product" Then
            ws.Range(str + "4:" + str + (MTUsedRange - 1).ToString).Copy()
            newSheet.Activate()
            newSheet.Range("A1").PasteSpecial()
            ws.Activate()
        ElseIf CType(ws.Cells(4, c), Microsoft.Office.Interop.Excel.Range).Value.ToString = "Foreign Amount" Then
            ws.Range(str + "4:" + str + (MTUsedRange - 1).ToString).Copy()
            newSheet.Activate()
            newSheet.Range("C1").PasteSpecial()
            ws.Activate()
            'ElseIf CType(ws.Cells(4, c), Microsoft.Office.Interop.Excel.Range).Value.ToString = "An Type" Then
            '    ws.Range(str + "4:" + str + (MTUsedRange - 1).ToString).Copy()
            '    newSheet.Activate()
            '    newSheet.Range("D1").PasteSpecial()
            '    ws.Activate()
        ElseIf CType(ws.Cells(4, c), Microsoft.Office.Interop.Excel.Range).Value.ToString = "Account" Then
            ws.Range(str + "4:" + str + (MTUsedRange - 1).ToString).Copy()
            newSheet.Activate()
            newSheet.Range("D1").PasteSpecial()
            ws.Activate()
        End If
    Next

@Deepak94,

On this sheet i need to paste the data.

Col B (doc Type ) to Col Z (Doc Type) ,
Col C to Col B, like wise

Ahtesham

i would love to use but i am very poor at vb. i didn’t get anything from your code…

ahtesham

@md.ahtesham,
Ok.
Could you please try below solution and let me know if it works or not.

create two array variable and assign values as below.
strArray1={B,C} (columns of first sheet1)
strArray2={Z,B} (columns of second sheet2)
read sheet2 along with the columns -> dtExcleSheet2

i=0
for each srtArray1
Read Column Activity -> sheet1 and range -> item.tostring+“1”
j=0
j=dtExcelSheet2.rows.count
for each outputOfAboveReadRangeActivity
Write Cell Activity -> Sheet2 and range -> strArray2(i).ToString+j.ToString
j=j+1
i=i+1

Thanks!