+ Reply to Thread
Results 1 to 7 of 7

Macro for division with absolute cell references to replace Indirect formula?

  1. #1
    Registered User
    Join Date
    04-06-2012
    Location
    India
    MS-Off Ver
    Pro Plus 2019
    Posts
    86

    Macro for division with absolute cell references to replace Indirect formula?

    Hi!

    I have a workbook where data in Row 4 is continuously and automatically being inserted from another sheet, so that data in Row4 becomes Row5 and fresh data is inserted in Row 4.

    I need to divide data of Row 4 by data in Row 13 and get the result in Row 2. I am currently using Indirect formula to keep absolute cell references for Row4/ Row 13.
    Please Login or Register  to view this content.
    But calculations are being slowed down if I use Indirect formula 300 times i.e. for Col. A to KO, due to the amount of complexity and data coming in continuously.

    I was wondering if someone could help me with a macro so that rather than using Indirect formula to keep absolute cell reference of dividing data in row 4 with data in Row 13, I could use a macro and get the result in Row 2.

    PS:

    Please do remember that I need it for 300 columns and not just for 1 column.

    Sample sheet with excel calculation and desired result attached.

    Regards,

    Naira
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Ontario Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Macro for division with absolute cell references to replace Indirect formula?

    Not sure why you are using indirect because it looks like just a regular division.
    But for the VBA, try this.
    It first gets the formulas then pastes then as values

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-06-2012
    Location
    India
    MS-Off Ver
    Pro Plus 2019
    Posts
    86

    Re: Macro for division with absolute cell references to replace Indirect formula?

    Hi Jason,

    Thank you for your reply. Your code works.

    However there are 2 hiccups:

    1. The code works on whatever is the current active sheet. So incase I want to call the code from some other sheet which is the current active sheet, the code over-writes the data on that sheet instead of the desired sheet. Can you please help me out with the code in specifying what sheet the code should run on?

    2. I need to run the code automatically every 20 seconds. Can you please help me out with this too?

    PS: The indirect function was used since a row with fresh data is first automatically inserted at Row 4 every 20 seconds, and then I always need to divide the contents of Row4 with Row13. In case I use a simple division function, when the new row is inserted at Row 4 the formula =b4/b13 OR =$b$4/$b$13 changes to =b5/b14 and so on... without the Indirect function.

    Regards,

    Naira
    Last edited by naira; 08-13-2013 at 03:39 PM.

  4. #4
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Ontario Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Macro for division with absolute cell references to replace Indirect formula?

    Here is the Application.OnTime method.
    And yea the indirect makes sense. It slipped my mind because I have been working with VBA more than worksheet functions lately.
    You just have to change "Sheet1" to the sheet you want.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-06-2012
    Location
    India
    MS-Off Ver
    Pro Plus 2019
    Posts
    86

    Re: Macro for division with absolute cell references to replace Indirect formula?

    Hi Jason,

    Almost there, as in, it runs if the Macro is applicable on the sheet it is called from, but gives a Run Time error '1004' Application defined or Object Defined error, and highlights the Rows:
    Please Login or Register  to view this content.
    if I change the value
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    and call the code from Sheet1

    Seems I have to define a variable but not sure what or how.

    If I remove the dot before .Range and change the formula to
    Please Login or Register  to view this content.
    it goes back to working only on the sheet that is currently active.

    Could you please be kind enough to check the sample file I am attaching for you to check with your code.

    Regards,

    Naira
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Ontario Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Macro for division with absolute cell references to replace Indirect formula?

    Ahh I see.
    It is because it is using relative references on the formulas.
    It has to be on the active sheet.
    I guess you could change the formulas to be placed by a loop.
    But I have a question for you.

    Does it matter if these totals are updated while you are not on the sheet?
    Just curious as to what the purpose is.
    Because if you are not on the sheet, there would have to be another macro or something that populates theses values.

  7. #7
    Registered User
    Join Date
    04-06-2012
    Location
    India
    MS-Off Ver
    Pro Plus 2019
    Posts
    86

    Re: Macro for division with absolute cell references to replace Indirect formula?

    Hi Jason.

    - Yes, the data is being populated in Row4 automatically by another macro. That was my first statement in my original post.
    I have a workbook where data in Row 4 is continuously and automatically being inserted from another sheet, so that data in Row4 becomes Row5 and fresh data is inserted in Row 4.
    - The requirement is that I am clubbing and monitoring various parameters of running machines on a real time basis and in case all/ most the parameters of a machine start changing dramatically, I will be able to compare the latest readings with the readings a few minutes ago and take preventive measures before they hit a critical breakdown level.

    - Not sure about the loop thing though/ how to place the macro in a loop. I can call the macro from within another macro later (had already tried that earlier but I was still getting the same error), but I still need a working solution to the above request. Can you please give a working solution/ attach a working sheet with your working macro?

    Tried looping with:
    Please Login or Register  to view this content.
    but this still works on the active sheet only.

    Then tried:

    Please Login or Register  to view this content.
    But this is giving the same error and for the same line as in my earlier post.


    Thanks for taking all the trouble.

    Regards,

    Naira
    Last edited by naira; 08-14-2013 at 01:31 PM.

+ 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] Replace absolute cell reference with Indirect cell reference in formula
    By Roothy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-11-2013, 04:46 AM
  2. [SOLVED] Absolute References in cell formula
    By Bernie Deitrick in forum Excel Formulas & Functions
    Replies: 25
    Last Post: 09-06-2005, 10:05 AM
  3. [SOLVED] Absolute References in cell formula
    By ah666 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-17-2005, 11:05 AM
  4. [SOLVED] RE: replace absolute references
    By bj in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-20-2005, 03:06 PM
  5. [SOLVED] replace absolute references
    By BorisS in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-20-2005, 03:06 PM

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