+ Reply to Thread
Results 1 to 9 of 9

How to autofill a formula when the cell references are variable.

  1. #1
    Registered User
    Join Date
    08-24-2016
    Location
    UK
    MS-Off Ver
    2007
    Posts
    6

    How to autofill a formula when the cell references are variable.

    Hi,

    I am writing a macro to autofill a formula down to the same number of rows as the row to the left of the cell that has been clicked on. I have found the below code to do this but it relies on the formula being entered only into row K and filling down to the number of rows in j. Is there anyway to write this so wherever the active cell starts, it will fill down the number of cells equal to the number of cells in the column to the left? In the data set I don't anticipate there to be blank cells.

    Please Login or Register  to view this content.
    Thanks,
    Alexis
    Last edited by Lumisheep; 08-26-2016 at 08:39 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: How to autofill a formula when the cell references are variable.

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: How to autofill a formula when the cell references are variable.

    Ah, and I should have said ... a) welcome to the forum and b) please take a few moments to read the forum rules



    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  4. #4
    Registered User
    Join Date
    08-24-2016
    Location
    UK
    MS-Off Ver
    2007
    Posts
    6

    Re: How to autofill a formula when the cell references are variable.

    Thank you that really helps!

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: How to autofill a formula when the cell references are variable.

    You're welcome.

  6. #6
    Registered User
    Join Date
    08-24-2016
    Location
    UK
    MS-Off Ver
    2007
    Posts
    6

    Re: How to autofill a formula when the cell references are variable.

    Hi,
    I just realised that the formula above only fills down to the 2 cells before the end. Sorry I didn't spot this before. This means there are two blank spaces at the end of each column whenever I use the macro. Is there anything I can add to the formula above to adjust it?

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: How to autofill a formula when the cell references are variable.

    Maybe try changing this
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-24-2016
    Location
    UK
    MS-Off Ver
    2007
    Posts
    6

    Re: How to autofill a formula when the cell references are variable.

    ooh, sort of embarrassing- sorry I realised I had accidentally changed the +1 to -1 at some point. The first formula worked perfectly. Thanks again.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: How to autofill a formula when the cell references are variable.

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Autofill two references in complex formula
    By rheriksen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-27-2014, 04:57 AM
  2. Autofill with cell references
    By MarginofBuffett in forum Excel General
    Replies: 1
    Last Post: 10-26-2010, 05:50 AM
  3. autofill a formula that references worksheet tabs
    By menziesthefish in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-29-2010, 10:50 AM
  4. Autofill cell references
    By stephen.ward in forum Excel General
    Replies: 7
    Last Post: 02-17-2010, 01:56 PM
  5. variable Cell references within formula
    By Macatk in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-18-2009, 08:48 PM
  6. Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  7. [SOLVED] More- AutoFill with Non-Seqeuntial Cell References ?
    By [email protected] in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-22-2005, 10:05 PM

Tags for this Thread

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