Change a specific code to generic in VB macro

  • Thread starter Thread starter Sue
  • Start date Start date
S

Sue

I have the following:

Selection.AutoFill Destination:=Range("BE2:BE567"), Type:=xlFillDefault
Range("BE2:BE567").Select

I would like to change the code to include all possible used cells to fill.
How do I do this?
 
Hi Sue:

Here's one approach.

Use a line of code like this to find the last used row:

LastRow = Range("B65536").End(xlUp).row OR
LastRow = ActiveCell.SpecialCells(xlLastCell).row

Then modify your code to this:

Selection.AutoFill Destination:=Range("BE2:BE" & Lastrow), Type:=xlFillDefault
Range("BE2:BE" & Lastrow).Select

Give that a whirl.

cheers,
gt
 
ooops - one slight change :
LastRow = Range("BE65536").End(xlUp).row OR
LastRow = ActiveCell.SpecialCells(xlLastCell).row

Then modify your code to this:

Selection.AutoFill Destination:=Range("BE2:BE" & Lastrow), Type:=xlFillDefault
Range("BE2:BE" & Lastrow).Select
 

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

Back
Top