autofill in a macro

M

Matt Houston

Hi there

I am trying to use a macro to format a spreadsheet. I have a column o
numbers, in the next column I need to put the same text next to eac
number/row, so I put the text in the first cell of the next column an
used autofill. This works fine except that when I look at the VBA i
has used this bit of code -> Selection.AutoFil
Destination:=ActiveCell.Range("A1:A761"), in other words it will fill
set number of cells and if my list of numbers is any shorter/longer th
next time I want to use the macro it will cause problems. Any ideas o
how I can get around this?

thank
 
B

Bernie Deitrick

Matt,

Change this
Selection.AutoFill Destination:=ActiveCell.Range("A1:A761")
To this, to match column B:
Selection.AutoFill
Destination:=ActiveCell.Range("A1",Range("B65536").End(xlUp)(1,0))

HTH,
Bernie
MS Excel MVP
 
B

Bernie Deitrick

Of course, those two line should be on one line, AND I missed the activecell
part:

Selection.AutoFill _
Destination:=Range(ActiveCell, ActiveCell(1, 2).End(xlDown)(1, 0))

Sorry about that,
Bernie
MS Excel MVP

Bernie Deitrick said:
Matt,

Change this
Selection.AutoFill Destination:=ActiveCell.Range("A1:A761")
To this, to match column B:
Selection.AutoFill
Destination:=ActiveCell.Range("A1",Range("B65536").End(xlUp)(1,0))

HTH,
Bernie
MS Excel MVP
 

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

Similar Threads

AutoFill Macro Issue 1
Autofill question 2
Autofill column values in formulas 4
Autofill: can it detect change in value? 3
AutoFill 1
Autofill in macro 5
Please help to copy in a range 3
autofill macro 1

Top