1

I have zero knowledge about Macro. Is there a kind of code I can use to copy data from several cells including its header to one cell. It looks like this:

This is the source table:

This is the source table

And this should be the output:

output table

4
  • Is the number of content rows static? Is it equal for all columns?
    – Akina
    Sep 14, 2018 at 7:12
  • Hi Akina, yes it is pretty static. I'm not sure if it is equal for all columns. Sep 14, 2018 at 7:14
  • it is pretty static. I'm not sure if it is equal for all columns. Does it mean that the whole source contains a static amount of rows (for example, 10 rows always), but some columns may contain a lot of empty cells? If so, are those empty cells at the end of table or they may posess in the start/middle of a column?
    – Akina
    Sep 14, 2018 at 7:22
  • Do you want results in Column or in a Cell ?? Sep 14, 2018 at 10:33

1 Answer 1

1

Here's the VBA code:

Sub copy_range_to_cell()
  Set rng = Range("A3:C4")
  For Each Column In rng.Columns
    For Each cell In Column.Cells
      Range("E4").Value = Range("E4").Value & cell.Text & Chr(10)
    Next cell
    Range("E4").Value = Range("E4").Value & Chr(10)
  Next Column
End Sub

Before:

enter image description here

After:

enter image description here

3
  • 1
    Nice it's working,, perfect 10 ☺ Sep 14, 2018 at 11:08
  • Thanks simlev. This is working perfectly. How about if I have contents in row 5 and I want to copy the same headers but should only copy the contents in row 5? Sep 20, 2018 at 2:31
  • Glad it helped, please don't forget to accept the answer. This further question about row 5 is not entirely clear to me, please add more details possibly accompanied by a screenshot. Consider opening a new question if applicable.
    – simlev
    Sep 20, 2018 at 7:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .