+ Reply to Thread
Results 1 to 4 of 4

Copy a formula down in a macro

  1. #1
    Sal
    Guest

    Copy a formula down in a macro

    I have information in column A and I wish to write a macro that:

    1. Populates cell B2 with a VLOOKUP formula
    2. The macro is then to copy the above formula down to the last active cell
    in column A

    I have tried so many things that I am in a bid of a muddle. Any suggestions
    will be very welcome.

    Thanks

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Just modify the formula to equal your lookup formula

    Sub Macro1()

    Dim LastRow As Long
    LastRow = Cells(Rows.Count, "a").End(xlUp).Row
    Range("a1").Value = "=b1+1"
    Range("a1:a1").AutoFill _
    Destination:=Range("A1:A" & LastRow), Type:=xlFillDefault
    End Sub

  3. #3
    Sal
    Guest

    Re: Copy a formula down in a macro

    Thank you so much - I just changed the cell references around a wee bit and
    it works perfectly.

    Your help is much appreciated!!

    "mudraker" wrote:

    >
    > Just modify the formula to equal your lookup formula
    >
    > Sub Macro1()
    >
    > Dim LastRow As Long
    > LastRow = Cells(Rows.Count, "a").End(xlUp).Row
    > Range("a1").Value = "=b1+1"
    > Range("a1:a1").AutoFill _
    > Destination:=Range("A1:A" & LastRow), Type:=xlFillDefault
    > End Sub
    >
    >
    > --
    > mudraker
    > ------------------------------------------------------------------------
    > mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
    > View this thread: http://www.excelforum.com/showthread...hreadid=548381
    >
    >


  4. #4
    Dave Peterson
    Guest

    Re: Copy a formula down in a macro

    dim LastRow as long
    with worksheets("sheet9999")
    lastrow = .cells(.rows.count,"A").end(xlup).row
    .range("B2:b" & lastrow).formula _
    = "=vlookup(a2,'sheet 333'!a:e,5,false)"
    end with

    will fill that range with a vlookup formula.

    Sal wrote:
    >
    > I have information in column A and I wish to write a macro that:
    >
    > 1. Populates cell B2 with a VLOOKUP formula
    > 2. The macro is then to copy the above formula down to the last active cell
    > in column A
    >
    > I have tried so many things that I am in a bid of a muddle. Any suggestions
    > will be very welcome.
    >
    > Thanks


    --

    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