excel vba - Code works in Module but not in worksheets Error 1004 -
was hoping recieve on bit of code below. works in module 1, not work in of worksheets. i've tried best limited knowledge haven't been able fix it.
sub lastrow() dim mcfpsheet worksheet set mcfpsheet = thisworkbook.worksheets("mcfp referrals ytd") dim lastrow long lastrow = mcfpsheet.range("i2").end(xldown).row mcfpsheet.range("r8") .autofill destination:=range("r8:r" & lastrow&) end mcfpsheet.range("s2") .autofill destination:=range("s2:s" & lastrow&) end mcfpsheet.range("t2") .autofill destination:=range("t2:t" & lastrow&) end mcfpsheet.range("u2") .autofill destination:=range("u2:u" & lastrow&) end mcfpsheet.range("v2") .autofill destination:=range("v2:v" & lastrow&) end mcfpsheet.range("w2") .autofill destination:=range("w2:w" & lastrow&) end end sub
i receive
error 1004
in .autofill destination:=range("r8:r" & lastrow&)
line.
according @sixthsense comment need specify worksheet destination, these with
statements don't make sense if one-liners.
it shorter using with
way:
sub lastrow() dim mcfpsheet worksheet set mcfpsheet = thisworkbook.worksheets("mcfp referrals ytd") dim lastrow long lastrow = mcfpsheet.range("i2").end(xldown).row mcfpsheet .range("r8").autofill destination:=.range("r8:r" & lastrow) .range("s2").autofill destination:=.range("s2:s" & lastrow) .range("t2").autofill destination:=.range("t2:t" & lastrow) .range("u2").autofill destination:=.range("u2:u" & lastrow) .range("v2").autofill destination:=.range("v2:v" & lastrow) .range("w2").autofill destination:=.range("w2:w" & lastrow) end end sub
note destination:=.range
refers mcfpsheet
sheet using leading .
before range
!
, removed &
lastrow&
don't see sense in it.
Comments
Post a Comment