Results 1 to 5 of 5

Autofill in VBA with a dynamic "Destination" range

Threaded View

  1. #1
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Autofill in VBA with a dynamic "Destination" range

    I'm trying to set up this macro to autofill in VBA:

    Sub filldateinfo()
     
    '   Format the new cells
        Range("D2").Select
        Selection.Copy
        Range("F2:G2").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
    '   Add the formulas to get the year and month
        Range("F2").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(OR(MID(RC4,3,1)=""."",MID(RC4,3,1)=""-"",MID(RC4,3,1)=""/""),RIGHT(RC4,4),IF(OR(MID(RC4,5,1)=""."",MID(RC4,5,1)=""-"",MID(RC4,5,1)=""/""),LEFT(RC4,4),""""))"
        Range("G2").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(OR(MID(RC4,3,1)=""."",MID(RC4,3,1)=""-"",MID(RC4,3,1)=""/""),LEFT(RC4,2),IF(OR(MID(RC4,5,1)=""."",MID(RC4,5,1)=""-"",MID(RC4,5,1)=""/""),RIGHT(RC4,2),""""))"
    '   Autofill to the end of the table
       Range("F2:G2").Select
       Selection.AutoFill Destination:=Range("F2:G8489")  'How do I make this dynamic based on the length of column A?
       Range("F2:G8489").Select  'How do I make this dynamic based on the length of column A?
    '   Replace the formulas with values
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    '   Re-arrange the table
        Columns("E:E").Select
        Application.CutCopyMode = False
        Selection.Cut Destination:=Columns("H:H")
        Columns("F:H").Select
        Selection.Cut Destination:=Columns("D:F")
        Range("A1").Select
     
    End Sub
    The length of the table will vary, so I need the autofill to determine it's own "Destination" value based on the length of column A.

    See attached for sample.

    Cheers,
    Attached Files Attached Files
    Last edited by ConneXionLost; 05-04-2011 at 04:35 PM.
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

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