+ Reply to Thread
Results 1 to 3 of 3

Last Row and Autofill for only 1 line as well as loads of lines.

  1. #1
    Registered User
    Join Date
    11-26-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Last Row and Autofill for only 1 line as well as loads of lines.

    Hi All,

    The below code is adding a cell in column G and adding a formular into G2.

    I then want to copy the formular down to the lastRow in any of columns A-C, it could just be column A if that worked.

    My issue is that this works fine if there is more than 2 lines of data, i.e the headings in row 1 and then some detial in line 2 & 3.

    If there is only 1 line of detail it errors. I know it is probably something stupid but i cant figure it out.

    Thanks in advance.

    Dim lastRow as Long

    Columns("G:G").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("G1").Select
    ActiveCell.FormulaR1C1 = "DUE DATE"
    Range("G2").Select
    ActiveCell.FormulaR1C1 = "=IF(RC[21]=""EXTENDED TERMS"",""EXT"",RC[34])"
    lastRow = Range("A:C").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Range("G2").AutoFill Destination:=Range("G2:G" & lastRow)

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Last Row and Autofill for only 1 line as well as loads of lines.

    Try this...

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    11-26-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Last Row and Autofill for only 1 line as well as loads of lines.

    Hi All,

    After hours of google it i found that an on error rsue next statement worked:

    Columns("G:G").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("G1").Select
    ActiveCell.FormulaR1C1 = "DUE DATE"
    Range("G2").Select
    ActiveCell.FormulaR1C1 = "=IF(RC[21]=""EXTENDED TERMS"",""EXT"",RC[34])"
    lastRow = Range("A:C").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    On Error Resume Next
    Range("G2").AutoFill Destination:=Range("G2:G" & lastRow)

+ 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