excel - Autofill in vba with value con a specific cell -
i'm trying macro autofill cells value cell (i have count if on cell) current code have, haven't gotten work:
sub idontknowwhatimdoing() dim nim integer dim nom integer nom = 6 nim = nom + cells("c2").value activesheet.range(cells(6, 1), cells(6, 4)).select selection.autofill destination:=activesheet.range(cells(6, 1), _ cells(6, 4)).select, type:=xlfilldefault activesheet.range(cells(nim, 1), cells(nim, 4)).select end sub
one reason getting error cell("c2").value
. can't (afaik) use cell()
that, instead use range("c2").value
. cells()
uses cells([column],[row])
. so, if want use cells()
(which can helpful later on in looping), range("c2")
same range(cells(3,2),cells(3,2))
.
also, it's idea reduce/negate use of .select
:
sub idontknowwhatimdoing() dim nim integer dim nom integer nom = 6 nim = nom + range("c2").value activesheet.range(cells(6, 1), cells(6, 4)).autofill range(cells(6, 1),cells(6, 4)), type:=xlfilldefault 'why .select next range? want it? activesheet.range(cells(nim, 1), cells(nim, 4)).select end sub
that still gives error, because source range , fill range same. takes a6:d6 , wants fill in a6:d6. if change second cell cells(7,4)
it works. fix range , you're go!
edit: assume don't want take range , fill same range. ...are trying take what's in a6, , copy b6, c6, , d6? or take what's in a6:d6 , paste like, f6:i6? also, want use nim , nom
in main part? they're set same ranges hard coded numbers.
Comments
Post a Comment