Sunday, 5 February 2017

excel - How to copy a range of cells to another column in VBA?

Working Environment: Excel 2013




Target: Copy C1:C9 to B11:B19. D1:D9 to B21:B29. E1:E9 to B31:B39.....



After copying all the range to column B, copy A1:A9 to A11:A19(A21:A29....)



My idea is that:
1. select a range by using something like



     range.end()



because in some of my sheets, there are only 4 test steps. so I need a syntax which can self inspect the used cells in a column.




  1. do a range copy to column B.

  2. leave 1 row in between considering about the page layout.



My piece of code is:



Worksheets("Master").Columns(3).UsedRange.Copy

Worksheets("Master").Range("B11").PasteSpecial


but seems like the Columns(i).UsedRange.Copy doesn't work. the pastespecial works.



My question is:



How to select the used range in columns? The number of columns are not fixed which means some of the sheets have 40 columns, but some of the other have maybe 30.



Thanks!




I attached one screenshot of the sheet for your reference.Screenshot of the sheet

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...