excel - I am trying to copy a selection from one worksheet to another using vba and style the new sheet but one set of column values is not copying over -
i can original column "u" copy on (which date field). literally else works 1 field, ideas why 1 field not copy over?
here's wrote far:
sub copiesandmovesreferraldatafromolab() cells.select range("d:d,c:c,e:e,am:am,f:f,r:r,ai:ai,aj:aj,u:u").select application.cutcopymode = false selection.copy workbooks.add activesheet.paste range("a1").select activecell.formular1c1 = "xxx" range("b1").select activecell.formular1c1 = "xxx" range("c1").select activecell.formular1c1 = "xxx" range("d1").select activecell.formular1c1 = "xxx" range("e1").select activecell.formular1c1 = "xxx" range("f1").select activecell.formular1c1 = "xxx" range("g1").select activecell.formular1c1 = "xxx" range("h1").select activecell.formular1c1 = "xxx" range("i1").select activecell.formular1c1 = "xxx" range("j1").select activecell.formular1c1 = "xxx" range("a1:j1").select selection.font.bold = true selection.font .themecolor = xlthemecolordark1 .tintandshade = 0 end selection.interior .pattern = xlsolid .patterncolorindex = xlautomatic .color = 10053222 .tintandshade = 0 .patterntintandshade = 0 end cells.select cells.entirecolumn.autofit end sub
not sure why column u wouldn't copy over, work objects instead, , supply destination range copy method, don't need 2 instructions, , you're not pasting on whatever random cell active in destination worksheet - if cell a1, header row overwriting first row of data you're pasting over:
dim sourcesheet worksheet set sourcesheet = activesheet dim targetbook workbook set targetbook = application.workbooks.add dim targetsheet worksheet set targetsheet = targetbook.worksheets(1) sourcesheet.range("d:d,c:c,e:e,am:am,f:f,r:r,ai:ai,aj:aj,u:u") .copy targetsheet.range("a2") end as rest... use with blocks work with given specific range, instead of successively .selecting each individual cell , working activecell macro-recorder "code":
dim headings() variant headings = array("column1","column2","column3", ..., "column10") targetsheet.range("a1:j1") .value = headings .font .bold = true .themecolor = xlthemecolordark1 .tintandshade = 0 end .interior .pattern = xlsolid .patterncolorindex = xlautomatic .color = 10053222 .tintandshade = 0 .patterntintandshade = 0 end .entirecolumn.autofit end i don't know how use variables , not (i'm not programmer)
you're writing code, you're programming. not knowing normal, you're here learn. long you're willing learn, nothing stop you. declare local variables dim, assign object references set keyword, specify option explicit @ top of every module, , you'll great!
Comments
Post a Comment