+ Reply to Thread
Results 1 to 11 of 11

VBA processes before needed cells are calculated

  1. #1
    Registered User
    Join Date
    07-26-2012
    Location
    Waikanae, Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    12

    VBA processes before needed cells are calculated

    I'm using a script from here: http://www.excelforum.com/excel-form...final-and.html

    The script basically gets a collection of cells and comma separates them with a final "and" (as the last comma)

    My problem is, the VBA script seems to be running before cell values are calculated. If I change student % scores (sheet 1 "Grades") then the "Top Subjects" column is what it should be just prior to the change of data.

    How can I make sure the script executes only when the cells have been fully calculated, so that the results appear accurate when data is updated?

    Please examine the attachment: autograder_lags.xlsm
    Last edited by LancerNZ; 05-23-2014 at 06:47 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA processes before needed cells are calculated

    Can you put the code in

    Please Login or Register  to view this content.
    b
    Last edited by alansidman; 05-23-2014 at 08:04 AM.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    07-26-2012
    Location
    Waikanae, Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: VBA processes before needed cells are calculated

    Thanks for the reply. I don't understand how to do what you are saying. Excel won't let me sandwich the function between Sub Worksheet_Calculate() and End Sub.

    Here's the function...

    Please Login or Register  to view this content.
    How do I apply what you've said to do?

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,851

    Re: VBA processes before needed cells are calculated

    Open the VBE. In the left window which lists your objects, click on the Worksheet you want to place the code in. Your window on the right will open blank. Click in the left address window and select worksheet. Now in the right address window, select calculate. Copy everything from your code except the First line and last line and paste in. SAVE
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Registered User
    Join Date
    07-26-2012
    Location
    Waikanae, Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: VBA processes before needed cells are calculated

    Quote Originally Posted by alansidman View Post
    ...Now in the right address window, select calculate...
    Sorry, I'm lost there; where is "calculate"? Here's a screenshot of my VBE.

    vbewherecalc.png

    I'm worried that you're asking me to post the function which relies on specified cells (e.g. rRange As Range) into a global function which might not know where to find them (when it references rRange) because you've asked me not to include the first line which defines rRange, but as I'm a noobie on anything Excel / VBE I'm following along with whatever you suggest.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,851

    Re: VBA processes before needed cells are calculated

    See the attached .VBE.jpg

    Define your rRange as a Dimension statement

    Please Login or Register  to view this content.
    Last edited by alansidman; 05-23-2014 at 02:25 PM.

  7. #7
    Registered User
    Join Date
    07-26-2012
    Location
    Waikanae, Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: VBA processes before needed cells are calculated

    Thanks for your reply. I've tried what you suggest but am now getting:
    Compile Error: Function call on left-hand side of argument must retutrn a Variant or object
    See image: error_vbfunction01.png

    This happens with the line of the code:
    Please Login or Register  to view this content.
    My code after following your instructions (did I put Dim rRange in the right place?) is:

    Please Login or Register  to view this content.
    Also, the previous module still exists which is a double up (how do I delete a module? Do I just erase all its lines?)

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,851

    Re: VBA processes before needed cells are calculated

    To delete a module, single click on the module in the left window, click on file and remove module.

  9. #9
    Registered User
    Join Date
    07-26-2012
    Location
    Waikanae, Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: VBA processes before needed cells are calculated

    Quote Originally Posted by alansidman View Post
    ...click on file and remove module.
    I can't. The remove option is greyed out.

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,851

    Re: VBA processes before needed cells are calculated

    Not sure why that is happening. An alternative means. Click on Alt +F8 to open the Macro selection window. Highlight your macro and click on delete. Does that work?

  11. #11
    Registered User
    Join Date
    07-26-2012
    Location
    Waikanae, Wellington, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: VBA processes before needed cells are calculated

    ALT+F8 brings up the a message box with the previous error message (above) saying that my modified VB is broken. (Compile Error: Function call on left-hand side of argument must return a Variant or object) Looks like we need to fix the newer procedure you directed me in making before we can delete other parts.

    I feel like there are a lot of dead ends being introduced. Could you please look at the file I attached in my original post? It's actually working except that the VB function gets called too early (it's processing immediately, before the cells feeding to it have had their own formulae updated)

    What's meant to be happening (in the excel worbook) is that the right column reports the highest subject score for each student (e.g. English). If a student has equal top score, it will report all of them with commas and "and" like this: "English, Maths and Cooking". The actual formula etc are run from the sheet labelled "BestWorst".

    Edit: I managed to delete the module by cutting and repasting the main VB code (attempt to flush any errors). Deleting the original module might not have been the best move. Now I'm getting Run-time error 424: Object required. I take it the formula cells are trying to call the module I've just deleted. Am going back to previous backup.

    Still don't know how to get the VB modules to not run after (not before) other cells in the workbook are updated. This might be a chicken egg problem, because other cells will use the output.
    Last edited by LancerNZ; 05-23-2014 at 06:18 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. Help needed Highlighting Cell in a grid from 2 calculated cells
    By steve77 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-03-2013, 06:25 PM
  2. Scheduling Data Needed and Bid Hours Calculated for a certain date
    By smirk100 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-17-2013, 06:52 PM
  3. Macro that processes subfolders
    By jimbofoxman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-17-2009, 02:36 PM
  4. How many excel processes can you open?
    By Stanley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-17-2006, 07:25 AM
  5. Display System Processes
    By Ashley in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-21-2005, 11:30 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