Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Autofill with Selected Cell in VBA

  1. #1
    New Member
    Join Date
    Jan 2008
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Autofill with Selected Cell in VBA

    Hello all,

    Until now I have been able to find all my answers through searches. As a VBA novice, it has been very helpful. I am stumped on this one, however. I am trying to autofill from the selected cell in Column C down. I would like it to stop at the last cell with data in Column B. This is the code I have so far:

    Range("C2").Select
    Selection.AutoFill Destination:=Range(Selection, Selection.End(xlDown))

    This does the autofill, but doesn't stop at the last cell with data in Column B.

    In the past I have use this code to acheive similar results:

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

    The problem with this code is that I will not always be starting in "C2". I need code that uses whatever the selected cell is.

    All help is appreciated. Thanks!

  2. #2
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling, Scotland
    Posts
    74,858
    Post Thanks / Like
    Mentioned
    55 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Autofill with Selected Cell in VBA

    I would suggest you still use the second code but alter it.

    One way to do say would perhaps be this.
    Code:
    ActiveCell.AutoFill Destination:=Range(ActiveCell.Address & ":C" & endRow)
    If posting code please use code tags.

  3. #3
    New Member
    Join Date
    Jan 2008
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Autofill with Selected Cell in VBA

    Perfect. Thank you!

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •