+ Reply to Thread
Results 1 to 3 of 3

Determine last row in columns 1-4 to copy a formula in column 5

  1. #1
    GEB
    Guest

    Determine last row in columns 1-4 to copy a formula in column 5

    I am importing external data into a workbook with formulas.
    I want to automate the copy-down for the formula in cell E1
    to the last populated row in columns 1-4.

  2. #2
    Dave Peterson
    Guest

    Re: Determine last row in columns 1-4 to copy a formula in column 5

    One way:

    Option Explicit
    Sub testme()

    Dim LastRow As Long
    Dim iCol As Long

    LastRow = 0
    With Worksheets("sheet1")
    For iCol = 1 To 4
    LastRow = Application.Max(LastRow, _
    .Cells(.Rows.Count, iCol).End(xlUp).Row)
    Next iCol

    .Range("e1:e" & LastRow).Formula = "=A1&b1&c1&d1"
    'or maybe:
    .Range("e1:e" & LastRow).FormulaR1C1 = .Range("e1").FormulaR1C1

    End With

    End Sub

    GEB wrote:
    >
    > I am importing external data into a workbook with formulas.
    > I want to automate the copy-down for the formula in cell E1
    > to the last populated row in columns 1-4.


    --

    Dave Peterson

  3. #3
    GEB
    Guest

    Re: Determine last row in columns 1-4 to copy a formula in column

    Dave,

    Thank you.
    I have tried both methods successfully.

    GEB

    "Dave Peterson" wrote:

    > One way:
    >
    > Option Explicit
    > Sub testme()
    >
    > Dim LastRow As Long
    > Dim iCol As Long
    >
    > LastRow = 0
    > With Worksheets("sheet1")
    > For iCol = 1 To 4
    > LastRow = Application.Max(LastRow, _
    > .Cells(.Rows.Count, iCol).End(xlUp).Row)
    > Next iCol
    >
    > .Range("e1:e" & LastRow).Formula = "=A1&b1&c1&d1"
    > 'or maybe:
    > .Range("e1:e" & LastRow).FormulaR1C1 = .Range("e1").FormulaR1C1
    >
    > End With
    >
    > End Sub
    >
    > GEB wrote:
    > >
    > > I am importing external data into a workbook with formulas.
    > > I want to automate the copy-down for the formula in cell E1
    > > to the last populated row in columns 1-4.

    >
    > --
    >
    > Dave Peterson
    >


+ 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