ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Concatenate column with variable to set a range (https://www.excelbanter.com/excel-discussion-misc-queries/167345-concatenate-column-variable-set-range.html)

april

Concatenate column with variable to set a range
 
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
--
aprilshowers

Dave Peterson

Concatenate column with variable to set a range
 
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.

april wrote:

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
--
aprilshowers


--

Dave Peterson

Kevin B

Concatenate column with variable to set a range
 
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.
--
Kevin Backmann


"april" wrote:

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
--
aprilshowers



All times are GMT +1. The time now is 02:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com