VBA Excel - deleting rows at specific intervals -
i new forum, bear me.
i have csv-file need apply vba-modules in order information need.
in short, have 3 macros following:
- create new row every 20th row
- take number cell above (column a) , fill blank space in new row number.
- sum numbers in column h 20 rows before new row total score. done subsequently long new rows appear (every 20th row).
is possible these 3 macros in single macro? make easier hand down others may need use these macros.
current code:
' step 1 sub insert20_v2() dim rng range set rng = range("h2") while rng.value <> "" rng.offset(20).resize(1).entirerow.insert set rng = rng.offset(21) wend end sub ' step 2 sub fillblanks() columns("a:a").select selection.specialcells(xlcelltypeblanks).select selection.formular1c1 = "=r[-1]c" end sub ' step 3 sub autosum() const sourcerange = "h" dim numrange range, formulacell range dim sumaddr string dim c long each numrange in columns(sourcerange).specialcells(xlconstants, xlnumbers).areas sumaddr = numrange.address(false, false) set formulacell = numrange.offset(numrange.count, 0).resize(1, 1) formulacell.formula = "=sum(" & sumaddr & ")" 'change formatting liking: formulacell.font.bold = true formulacell.font.color = rgb(255, 0, 0) c = numrange.count next numrange end sub
thank help. best,
helge
that should'nt hard.
public sub main() 'deklaration dim rng range const sourcerange = "h" dim numrange range, formulacell range dim sumaddr string dim c long 'loop trough rows set rng = range("h2") while rng.value <> "" rng.offset(20).resize(1).entirerow.insert set rng = rng.offset(21) wend 'fill blank rows in columns("a:a").select selection.specialcells(xlcelltypeblanks).select selection.formular1c1 = "=r[-1]c" each numrange in columns(sourcerange).specialcells(xlconstants, xlnumbers).areas sumaddr = numrange.address(false, false) set formulacell = numrange.offset(numrange.count, 0).resize(1, 1) formulacell.formula = "=sum(" & sumaddr & ")" 'change formatting liking: formulacell.font.bold = true formulacell.font.color = rgb(255, 0, 0) c = numrange.count next numrange end sub
Comments
Post a Comment