EXCEL VBA, inserting blank row and shifting cells -
i'm having trouble entering entire blank row. i'm trying shift columns a-ad (four columns past z).
currently cells a-o has content. cells o-ad blank. i'm running macro put data right of current data (column o).
i can insert row using
dfind1.offset(1).entirerow.insert shift:=xldown
but seems shift down a-o. i've manage shift down o-ad using loop
dfind1 range d = 1 15 dfind1.offset(2, (d + 14)).insert shift:=xldown next d
is there way shift down 30 cells vs 15? similarly, want shift 15 cells right. have loop setup that.
as rest of code, below. merging 2 excel sheets bases on finding match in column a. i've marked problem area. rest of code works part.
sub combiner() dim c range, d long, cfind range, x, y, zed, dest range, cfind1 range, dfind range, _ dfind1 range, crow, x_temp, y_temp on error resume next worksheets("sheet3").cells.clear worksheets("sheet1") .usedrange.copy worksheets("sheet3").range("a1") end worksheets("sheet2") each c in range(.range("a3"), .range("a3").end(xldown)) x = c.value y = c.next set cfind = .cells.find(what:=y, lookat:=xlwhole) .range(cfind.offset(0, -1), cfind.end(xltoright)).copy worksheets("sheet3") set dfind1 = .cells.find(what:=x, lookat:=xlwhole) if dfind1 nothing goto copyrev '************************************************************** '************************************************************** 'this problem area 'i'm having trouble inserting blank row dfind1.offset(1).entirerow.insert shift:=xldown d = 1 15 dfind1.offset(1).insert shift:=xltoright next d d = 1 15 dfind1.offset(2, (d + 14)).insert shift:=xldown next d '************************************************************** '************************************************************** end 'sheet3 goto nextstep copyrev: worksheets("sheet3") x_temp = .cells(rows.count, "a").end(xlup).row y_temp = .cells(rows.count, "p").end(xlup).row if y_temp > x_temp goto lr_ed lmaxrows = x_temp goto lrcont lr_ed: lmaxrows = y_temp lrcont: .range(("p" & lmaxrows + 1)).pastespecial worksheets("sheet2").range(cfind.offset(0, -1), cfind.offset(0, 0)).copy .range(("a" & lmaxrows + 1)).pastespecial end 'sheet3 nextstep: next lnglast = range("a" & rows.count).end(xlup).row worksheets("sheet3").sort .sortfields.clear .sortfields.add key:=range("a1:a2" & lnglast), sorton:=xlsortonvalues, order:=xlascending, dataoption:=xlsortnormal .setrange range("b3:z" & lnglast) .header = xlyes .matchcase = false .orientation = xltoptobottom .sortmethod = xlpinyin .apply end end 'sheet2 application.cutcopymode = false end sub
if want shift down can use:
rows(1).insert shift:=xlshiftdown
similarly shift over:
columns(1).insert shift:=xlshiftright
Comments
Post a Comment