Excel VBA Range variables and Autofill -
i'm adding columns end of table. first headings , formulas in column underneath. want autofill formulas whole list. believe variable declaration problem. keep on getting error @ autofill section @ bottom.
dim lastcol long, lastrow long dim ooscol long, lcell long dim lrange range dim ws worksheet set ws = application.activeworkbook.activesheet ws .name = "summary" lastcol = .cells(51, .columns.count).end(xltoleft).column .cells(51, lastcol + 1).value = "oos no soo" .cells(52, lastcol + 1).formular1c1 = "=if((rc[-21]=4)*and(rc[-20]=0)*and(rc[-19]=0)*and(rc[-3]=""roster"")*and(rc[-4]=""listed""),1,"""")" .cells(51, lastcol + 2).value = "oos soo" .cells(52, lastcol + 2).formular1c1 = "=if((rc[-22]=4)*and(rc[-21]>0)*and(rc[-20]>0)*and(rc[-4]=""roster"")*and(rc[-5]=""listed""),1,"""")" .cells(51, lastcol + 3).value = "soh no soo" .cells(52, lastcol + 3).formular1c1 = "=if((rc[-23]=4)*and(rc[-22]>0)*and(rc[-21]=0)*and(rc[-5]=""roster"")*and(rc[-6]=""listed""),1,"""")" .cells(51, lastcol + 4).value = "negative stock" .cells(52, lastcol + 4).formular1c1 = "=if((rc[-24]=4)*and(rc[-23]<0)*and(rc[-6]=""roster"")*and(rc[-7]=""listed""),1,"""")" .cells(51, lastcol + 5).value = "overstock" .cells(52, lastcol + 5).formular1c1 = "=if((rc[-25]=4)*and(rc[-21]>14)*and(rc[-7]=""roster"")*and(rc[-8]=""listed""),1,"""")" .cells(51, lastcol + 6).value = "dormant stock" .cells(52, lastcol + 6).formular1c1 = "=if((rc[-26]=4)*and(rc[-25]>0)*and(rc[-24]>10)*and(rc[-8]=""roster"")*and(rc[-9]=""listed""),1,"""")" .cells(51, lastcol + 7).value = "outdated stock counts" .cells(52, lastcol + 7).formular1c1 = "=if((rc[-27]=4)*and(rc[-26]<>0)*and(rc[-17]>30)*and(rc[-9]=""roster"")*and(rc[-10]=""listed""),1,"""")" .cells(51, lastcol + 8).value = "total issues" .cells(52, lastcol + 8).formular1c1 = "=sum(rc[-7]:rc[-1])*and(rc[-10]=""roster"")*and(rc[-11]=""listed"")" .range("a51", cells(51, columns.count).end(xltoright)).specialcells(xlcelltypeconstants).interior.color = rgb(0, 32, 96) .range("a51", cells(51, columns.count).end(xltoright)).specialcells(xlcelltypeconstants).font.color = vbwhite end ws lastcol = .cells(51, .columns.count).end(xltoleft).column ooscol = .cells(52, lastcol - 8) lastrow = .cells(rows.count, "a").end(xlup).row lcell = .cells(lastrow, lastcol) end lrange = range(ooscol, lcell).select selection.autofill destination:=range(ooscol, lcell)
i managed fix following code different site. see last line of code. that's worked.
dim lastcol long, lastrow long dim ws worksheet set ws = application.activeworkbook.activesheet ws .name = "summary" lastcol = .cells(51, .columns.count).end(xltoleft).column .cells(51, lastcol + 1).value = "oos no soo" .cells(52, lastcol + 1).formular1c1 = "=if((rc[-21]=4)*and(rc[-20]=0)*and(rc[-19]=0)*and(rc[-3]=""roster"")*and(rc[-4]=""listed""),1,"""")" .cells(51, lastcol + 2).value = "oos soo" .cells(52, lastcol + 2).formular1c1 = "=if((rc[-22]=4)*and(rc[-21]>0)*and(rc[-20]>0)*and(rc[-4]=""roster"")*and(rc[-5]=""listed""),1,"""")" .cells(51, lastcol + 3).value = "soh no soo" .cells(52, lastcol + 3).formular1c1 = "=if((rc[-23]=4)*and(rc[-22]>0)*and(rc[-21]=0)*and(rc[-5]=""roster"")*and(rc[-6]=""listed""),1,"""")" .cells(51, lastcol + 4).value = "negative stock" .cells(52, lastcol + 4).formular1c1 = "=if((rc[-24]=4)*and(rc[-23]<0)*and(rc[-6]=""roster"")*and(rc[-7]=""listed""),1,"""")" .cells(51, lastcol + 5).value = "overstock" .cells(52, lastcol + 5).formular1c1 = "=if((rc[-25]=4)*and(rc[-21]>14)*and(rc[-7]=""roster"")*and(rc[-8]=""listed""),1,"""")" .cells(51, lastcol + 6).value = "dormant stock" .cells(52, lastcol + 6).formular1c1 = "=if((rc[-26]=4)*and(rc[-25]>0)*and(rc[-24]>10)*and(rc[-8]=""roster"")*and(rc[-9]=""listed""),1,"""")" .cells(51, lastcol + 7).value = "outdated stock counts" .cells(52, lastcol + 7).formular1c1 = "=if((rc[-27]=4)*and(rc[-26]<>0)*and(rc[-17]>30)*and(rc[-9]=""roster"")*and(rc[-10]=""listed""),1,"""")" .cells(51, lastcol + 8).value = "total issues" .cells(52, lastcol + 8).formular1c1 = "=sum(rc[-7]:rc[-1])*and(rc[-10]=""roster"")*and(rc[-11]=""listed"")" .range("a51", cells(51, columns.count).end(xltoright)).specialcells(xlcelltypeconstants).interior.color = rgb(0, 32, 96) .range("a51", cells(51, columns.count).end(xltoright)).specialcells(xlcelltypeconstants).font.color = vbwhite end ws lastrow = .cells(rows.count, "a").end(xlup).row end cells(52, lastcol + 1).resize(1, 8).autofill destination:=range(cells(52, lastcol + 1), cells(lastrow, lastcol + 8))
Comments
Post a Comment