Autofill a specific range size

I am trying to rewrite this, however I would like to use ActiveCell instead of A2, and autofill when there is a value in the cell to the right of the activecell.  How would I rewrite this?

Set MyRange = Range(Range("A2"), Range("A" & Range("B2").End(xlDown).Row))
    Range("A2").AutoFill Destination:=MyRange

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
I'm assuming you are looking for something like this...

    Dim myrange As Range, lrow As Long

    If ActiveCell.Offset(0, 1).Value <> "" Then
        lrow = Cells(Cells.Rows.Count, ActiveCell.Column).End(xlUp).Row
        Set myrange = Range(ActiveCell.Address & ":" & Cells(lrow, ActiveCell.Column).Address)
        ActiveCell.AutoFill Destination:=myrange

    End If

Open in new window


pls try

Sub macro()
If ActiveCell.Offset(0, 1) <> "" Then
    Set myRange = Range(ActiveCell, Cells(ActiveCell.Offset(0, 1).End(xlDown).Row, ActiveCell.Column))
        ActiveCell.AutoFill Destination:=myRange
End If
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Roy CoxGroup Finance ManagerCommented:
I like to use ISEMPTY

Option Explicit

Sub x()
    Dim MyRange As Range

    If Not IsEmpty(ActiveCell.Offset(, 1)) Then
        Set MyRange = Range(ActiveCell, ActiveCell.End(xlDown))
        ActiveCell.Offset(, 1).AutoFill MyRange.Offset(, 1)
    End If
End Sub

Open in new window

RWayneHAuthor Commented:
All good solutions..  Like offset better, just because I am used to it.  Split up pts to all.  Thanks!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.