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?
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
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.
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
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.
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?
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.
Bookmarks