I have some count and based on my count it has to insert rows and write cell values and append it

For example i have

i have one sheet like this

slno name name2 name3 name4 age age1 age3 age4
1 karl john 30 20
2 Drake Tim rock vicky 20 40 22 32

i want like this in excel sheet output

slno name Age
1 karl 30
2 john 20
3 Drake 20
4 Tim 40
5 rock 22
6 vicky 32
image

so how to do this?

  • Read Range into a dt_Original
  • For Each Row in Data Table dt_Original
    ** Add Data Row to dt_Final with currentRow(“name”).ToString and currentRow(“age”).ToString as your values
    ** Add Data Row to dt_Final with currentRow(“name2”).ToString and currentRow(“age2”).ToString as your values
    ** Add Data Row to dt_Final with currentRow(“name3”).ToString and currentRow(“age3”).ToString as your values
    ** Add Data Row to dt_Final with currentRow(“name4”).ToString and currentRow(“age4”).ToString as your values
    // End For Each
  • Write Range to a new sheet

If it’s always going to be name, name2, name3 etc you could compact the middle steps:

** For Each in {“”,“2”,“3”,“4”}
*** Add Data Row to dt_Final with currentRow(“name” + item).ToString and currentRow(“age” + item).ToString as your values

That way it automatically appends “”, 2, 3, or 4 to the column names from dt_Original

Hi sathish
This one will work sure

Try this

1 Like