Results 1 to 7 of 7

Autofill a Dynamic Selection

Threaded View

  1. #1
    Registered User
    Join Date
    06-26-2009
    Location
    South Africa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Autofill a Dynamic Selection

    Hi

    I have looked around quite a bit and am looking for a way to fill down a pre-selected range of cells down until the last row that is defined by column A
    The most common type of autofill solution is as stated below, but that is not what I am looking for. It needs to autofill based on the cells that are currently selected (it can be one cell, three cells etc...).
    Dim LastRow As Long
    
    LastRow = Range("A65536").End(xlUp).Row
    
    
    Selection.AutoFill Destination:=Range("A1:C" & LastRow&), Type:=xlFillDefault
    However, the problem is that it is defined by autofilling from A1:C25 (as an example), but the cells that need be autofilled may not always be in columns A:C

    I am using the following code. It does the job but it is not efficient. I would like to take out the last two lines and just use the "Selection.AutoFill Destination:=Range(Selection, Selection.End(xlDown)), Type:=xlFillDefault" to take down to correct line (and not the end of the sheet as is currently doing

    Assume that cells are pre-selected or highlighted before running the macro.

    In my attachment, I have selected the last cells in columns E:C for ease

    Sub Autofill_Selection()
    '
    'AUTOFILL
    
    Dim LastRow As Long
    LastRow = Range("A65536").End(xlUp).Row
       
    Selection.AutoFill Destination:=Range(Selection, Selection.End(xlDown)), Type:=xlFillDefault
       
    Range(Range("A65536"), Range("A65536").End(xlUp).Offset(1, 0)).Select
    Selection.EntireRow.Delete
    
    '
    End Sub
    View my attachment as an example

    Thanks in advance for the help
    Attached Files Attached Files
    Last edited by georgeanaprop; 07-05-2010 at 07:45 AM. Reason: Changed tags HTML - CODE

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1