AutoFill a Range

S

Steve C

I have an Inputbox that asks for the number of couples attending an event.
If 50 is the value (stored in the variable NoCouples), and cell A1 already
contains "Couple01", I would like cell A1 to be autofilled down as follows:

Couple01
Couple02
Couple03
..
..
..
Couple50

Recording a macro that does this gives me the following line of code:
Selection.Autofill Destination:=Range("A1:A50"), Type:=xlFillDefault

How do I word my code to substitute NoCouples for A50? I've tried the
following to no avail:
Selection.Autofill Destination:=Range("A1:A + NoCouples"),
Type:=xlFillDefault

Thanks!

Steve C
 
B

bpeltzer

Take the NoCouples outside the quotes to have VB replace the string with the
value:
Selection.Autofill Destination:=Range("A1:A" & NoCouples)
 
J

Jef Gorbach

try this:
Selection.Autofill Destination:=Range("A1:A" & NoCouples),
Type:=xlFillDefault
 

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


Top