Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Want a macro for multiple columns on current macro for column

1 view
Skip to first unread message

Valerie

unread,
Feb 23, 2009, 12:26:01 PM2/23/09
to
I am currently using the following macro in many of my worksheets and love
the time it saves. It's for one column. My question is, can this be
modified to do 2 or more columns?

Dim endRow As Long
endRow = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2").AutoFill Destination:=Range("A2:A" & endRow)

I have formulas in A2 and B2 and want to autofill at the same time instead
of separately. I tried modifying (Range("A2:B2"),etc.) but can't get it to
work.

Any help would be greatly appreciated!

Rick Rothstein

unread,
Feb 23, 2009, 12:42:17 PM2/23/09
to
The best I can see, the code you posted won't work for your original set up
because it is searching for the endRow in the same column you want to
AutoFill. Assuming that the 1 in the endRow calculation is actually some
other column (I'll use 3 for this example), then you can do this to
accomplish what you want...

Dim endRow As Long
endRow = Cells(Rows.Count, 3).End(xlUp).Row
Range("A2:B2").AutoFill Destination:=Range("A2:B" & endRow)

Notice column designation after the colon has been changed to B in BOTH
Range function calls.

--
Rick (MVP - Excel)


"Valerie" <Val...@discussions.microsoft.com> wrote in message
news:C0FC76D6-D4A7-4F81...@microsoft.com...

JLGWhiz

unread,
Feb 23, 2009, 1:07:01 PM2/23/09
to
How about:

Dim endRow As Long
endRow = Cells(Rows.Count, 1).End(xlUp).Row

Range("A2").AutoFill Destination:=Range("A2:B" & endRow)

JLGWhiz

unread,
Feb 23, 2009, 1:16:01 PM2/23/09
to
It only works one column at a time.

Valerie

unread,
Feb 23, 2009, 2:30:00 PM2/23/09
to
Perfect!! Works just like I want it to! FYI - I left the endRow as Col 1
and it works!
0 new messages