Results 1 to 3 of 3

Code to auto populate a relative formula into a column

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-30-2007
    Location
    London, UK
    MS-Off Ver
    Microsoft Office 2007
    Posts
    317

    Smile Code to auto populate a relative formula into a column

    Hi All

    I have a report that I run off a database and extract to Excel.

    It has 3 fields: Title; FirstName; LastName. For example sake lets say they are in columns A, B, C. Now in D I have a fieldname of FullName and in D2 onwards the formula: =A2&" "&B2&" "&C2.

    Now I currently manually type the formula and drag it down to the same row as the last entry in the first 3 columns so that I get the full title in one cell.

    I wanted to know how I could enter the the formula above in column D so that it automatically does this for me?

    I tried to record a Macro as a test for column D setting the field name in D1 and the formula in D2 and got the following:
    Range("D1").FormulaR1C1 = "FullName"
        Range("D2").Select
        ActiveCell.FormulaR1C1 = "=RC[-7]&"" ""&RC[-6]&"" ""&RC[-5]"
        Range("D3").Select
    How can I copy this down in a Macro only to the last populated row in columns A, B & C?

    I have a piece of code to highlight a range from A2 to the last entry as so:
    Range("A2").Select
        Range("A2", (Cells(65536, ActiveCell.Column).End(xlUp))).Select
        Selection.Copy
    How can I use the above code as the range that needs the formula adding in column D as I am worried if I don't measure the range the macro will simply populate until it hits row 65536?

    I would be grateful for some guidance.

    Thanks.
    Last edited by Zyphon; 03-13-2009 at 01:19 PM.
    Best Regards.

    Michael
    -----------------------------------
    Windows Vista, Microsoft Office 2007

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