excel - Copy range of cells including border formatting x number of times -
i have sheet contains rows of information include borders. information in rows 1 3 on sheet2. make macro copy information onto sheet3 , paste row1 on sheet3 row4 on sheet3 in row8 on sheet2 , same further down sheet , copy on , on again until have correct amount of copies have specified in cell c5 on sheet1. if have x in cell c5 on sheet1 able paste row of information including boarders onto sheet3 x times. have basic understanding of vba , have looked @ other examples cannot work out how , retain borders.
i hope explanation makes sense. possible?
thanks greg
try this
notes:
change copy area on sheet 2: first_row, first_col, total_rows, , total_cols
cell c5 expected on sheet 1
sheet 3 deleted every time run macro
it's hard read keep shorter, can provide details if interested
option explicit public sub copyrange() const first_row long = 1: const total_rows long = 3 const first_col long = 1: const total_cols long = 3 dim totalcopies long, long, sh worksheet application.screenupdating = false sheets("sheet3").cells.delete totalcopies = sheets("sheet1").range("c5").value2 sheets("sheet2") 'copy .range( _ .cells(first_row, first_col), _ .cells(first_row + total_rows - 1, total_cols) _ ).copy end = 1 totalcopies 'paste * value in c5 sheets("sheet3").cells(((total_rows + 1) * (i - 1)) + 1, first_col).pastespecial next application .cutcopymode = false .screenupdating = true end end sub
Comments
Post a Comment