+ Reply to Thread
Results 1 to 9 of 9

Autofill help

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Autofill help

    I am having trouble and I think the answer is simple, but I cannot find it or figure it out. I have a table, say 3 rows x 3 columns. I have vba that when I doubleclick on a row, it inserts a new row below where I clicked and copies the values from the cells above to the new row. What I want is code for column 3 to fill the cell below so the number in say cell C1 increases by 1 and is put in the new cell C2. This needs to be variable as the table grows, so that if I doubleclick on row 20, which then adds a new row below and copies the values from above except for column 3, which will autofill the cell value from the row clicked on, add 1 and put that value in the cell below. Thanks for any help.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,883

    Re: Autofill help

    Post your code and, ideally, a sample workbook.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Re: Autofill help

    Sure, pretty simple code, but it's the autofill I can't figure out. So the code inserted a row and copied the cells, thus C3=C2, but what I want is when it
    inserts the new row, it fills like C7 did from C6.
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True   'Eliminate Edit status due to doubleclick
    
        ActiveCell.Offset(1, 0).EntireRow.Insert
        ActiveCell.EntireRow.Copy ActiveCell.Offset(1, 0).EntireRow
        
    End Sub
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Re: Autofill help

    I am trying this code, which is close, but it puts the value at the end of the column, not in the blank cell in the newly created row.
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim LR As Long
    Cancel = True   'Eliminate Edit status due to doubleclick
    
        ActiveCell.Offset(1, 0).EntireRow.Insert
        ActiveCell.EntireRow.Copy ActiveCell.Offset(1, 0).EntireRow
        ActiveCell.Offset(1, 0).ClearContents
       
    LR = Range("G" & Rows.Count).End(xlUp).Row
    Range("G" & LR).autofill Destination:=Range("G" & LR).Resize(2)
    
    End Sub

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Autofill help

    Maybe this

    With Target
        .Offset(1).EntireRow.Insert
        Range("a" & .Row).Resize(, 2).Copy Range("a" & .Row).Offset(1).Resize(, 2)
        Range("c" & .Row).AutoFill Destination:=Range("c" & .Row & ":" & "c" & .Offset(1).Row)
    End With
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  6. #6
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Re: Autofill help

    Quote Originally Posted by mike7952 View Post
    Maybe this

    With Target
        .Offset(1).EntireRow.Insert
        Range("a" & .Row).Resize(, 2).Copy Range("a" & .Row).Offset(1).Resize(, 2)
        Range("c" & .Row).AutoFill Destination:=Range("c" & .Row & ":" & "c" & .Offset(1).Row)
    End With
    Thanks mike7952! Pretty well what I need, other than column B not copying, but I might be able to get that. I tried it in combo with what I had and it seemed to work. Great!

  7. #7
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Autofill help

    Thanks mike7952! Pretty well what I need, other than column B not copying, but I might be able to get that. I tried it in combo with what I had and it seemed to work. Great!
    On your uploaded example workbook column B is coping for me

  8. #8
    Forum Contributor
    Join Date
    08-22-2009
    Location
    Manitoba
    MS-Off Ver
    Office 2010
    Posts
    524

    Re: Autofill help

    Quote Originally Posted by mike7952 View Post
    On your uploaded example workbook column B is coping for me
    Yes it does and now I have it figured out for the true table I am using! Thanks!!

  9. #9
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Autofill help

    Your welcome

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Autofill base on Active Cell and Autofill by row count of another sheet
    By enyak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-19-2014, 10:06 PM
  2. [SOLVED] Very small AutoFill macro showing "AutoFill methode of range class failed" why ?
    By nur2544 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2013, 10:21 PM
  3. Replies: 0
    Last Post: 09-17-2012, 08:24 AM
  4. Macro for Autofill removes header info when there is no data to autofill
    By esturan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2012, 01:42 PM
  5. Autofill problem or is it not autofill?
    By Pat Feasey in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 02-14-2011, 02:21 PM
  6. Replies: 1
    Last Post: 06-17-2005, 04:05 PM
  7. Replies: 0
    Last Post: 03-02-2005, 12:06 PM

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