+ Reply to Thread
Results 1 to 6 of 6

autofill to variable destination

Hybrid View

katmison autofill to variable... 08-30-2009, 12:50 PM
ravishankar re: autofill to variable... 08-30-2009, 01:20 PM
shg re: autofill to variable... 08-30-2009, 01:49 PM
katmison re: autofill to variable... 08-30-2009, 05:01 PM
shg re: autofill to variable... 08-30-2009, 05:43 PM
katmison re: autofill to variable... 08-30-2009, 06:57 PM
  1. #1
    Registered User
    Join Date
    04-26-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    18

    autofill to variable destination

    I have the following code that was achieved using the macro recorder. The only problem I am running into is that during the autofill command, there are never the same amount of rows to autofill. It could be as few as 5 rows and as many as there are rows on the spreadsheet. When I recorded the macro there were 953 lines, and unfortunately I cannot figure out how to change the specific destination of 953 to a variable destination determined by when data ends.

    Here is the code I currently have:
    Sub ConcatenateHighlight()
    '
    ' ConcatenateHighlight Macro
    '
    
    '
        Columns("C:C").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("C1").Select
        ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[-2],RC[-1])"
        Range("C1").Select
        Selection.AutoFill Destination:=Range("C1:C953")
        Range("C1:C953").Select
        Range("F1").Select
        ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[-2],RC[-1])"
        Range("F1").Select
        Selection.AutoFill Destination:=Range("F1:F953")
        Range("F1:F953").Select
        Range("C:C,F:F").Select
        Range("F1").Activate
        Selection.FormatConditions.AddUniqueValues
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        Selection.FormatConditions(1).DupeUnique = xlDuplicate
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 65535
            .TintAndShade = 0
        End With
        Selection.FormatConditions(1).StopIfTrue = False
        Range("D1").Select
    End Sub
    Thanks!
    Last edited by katmison; 08-30-2009 at 06:58 PM. Reason: to mark as solved

  2. #2
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    re: autofill to variable destination

    Hi
    Try
    Selection.AutoFill Destination:=Range("C1:C" & Range("C65536").end(xlup).row)
    Ravi

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    re: autofill to variable destination

    Try this:
    Sub ConcatenateHighlight()
        Dim nRow As Long
        
        nRow = Cells(Rows.Count, "C").End(xlUp).Row
        
        Columns("C").Insert
        With Range("(C:C, F:F) 1:" & nRow)
            .FormulaR1C1 = "=RC[-2] & RC[-1]"
            .FormatConditions.AddUniqueValues
            .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
            .FormatConditions(1).DupeUnique = xlDuplicate
            With .FormatConditions(1).Interior
                .PatternColorIndex = xlAutomatic
                .Color = 65535
                .TintAndShade = 0
            End With
            .FormatConditions(1).StopIfTrue = False
        End With
    End Sub
    Last edited by shg; 09-03-2009 at 01:21 PM. Reason: changed range construct
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    04-26-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    18

    re: autofill to variable destination

    Shg,
    I tried the code you gave me and it errored on this line:
    With Range("C1,F1").Resize(nRow)
    The error stated "Run Time error '1004' Application-defined, or Object-defined error".

    Help?

    Thanks!

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    re: autofill to variable destination

    Hmm. Edited, try again.

  6. #6
    Registered User
    Join Date
    04-26-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    18

    re: autofill to variable destination

    Oh, thank you so much! That did the trick! Going back now to edit and mark as solved.

+ Reply to Thread

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