+ Reply to Thread
Results 1 to 6 of 6

Copy formula and change row number in VBA

  1. #1
    Registered User
    Join Date
    03-04-2008
    Posts
    14

    Copy formula and change row number in VBA

    Hi

    I want to copy the formula in column "C" to each row, and change the row number each time i add a new row with data. Anyone know how to do this?

    I know this won't work, but this is so that you may better understand what I want.

    Please Login or Register  to view this content.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: Copy formula and change row number in VBA

    why would you want to do this through VBA when, if you right the formula correctly, you could probably just have the formula self-adjust itself?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645
    Do you need the formula?

    You could just do the calculation in the code and put the result in the cell.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    03-04-2008
    Posts
    14

    Re: Copy formula and change row number in VBA

    I've made a userform for the user to type in data that will be added to a database. In one column i want a formula that uses the data from other columns on that row. I can copy the formula down manually, but it wouldn't be very efficient to do that for each record.

    So basically, what i need is some kind of way to get the program to understand what row number the current record is on and then create the formula with that rownumber.

  5. #5
    Registered User
    Join Date
    03-04-2008
    Posts
    14

    Re: Copy formula and change row number in VBA

    That would work for that example, but I also need something for the other more advanced formulas.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Copy formula and change row number in VBA

    Just copy the formula from the row above, Excel will automatically change the row numbers just as it does when you copy a formula manually.
    Please Login or Register  to view this content.

+ 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