Concatenate column with variable to set a range

A

april

i have a macro which finds the last row and returns the value Last Row. i
want to use this info to auto fill a range - Selection.AutoFill
Destination:=Range("B10:B & LastRow"). I get an error message when i try
this. should i name the variable LastRow at the beginning of the macro? or
is there something wrong with the placement of the quote marks?

thanks in advance for your help
 
D

Dave Peterson

Maybe it's not the destination:= portion's fault.

What's selected?

If you're trying to fill the range and you know what it is, you might as well be
specific:

Dim LastRow as long
with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
.range("b10").autofill _
destination:=.range("B10:B" & lastrow)
end with

I used column A to determine the last row and filled B10 down to that last row.
 
K

Kevin B

Change Range("B10:B & LastRow") to the following:

Range("B10:B" & LastRow)

If you still get an error check to see if the the first line in your module
says "Option Explicit" and if it does you'll have to declare the LastRow
variable with a Dim statement before you can assign a value to it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top