I am working on an interactive Excel project.
I have a series of UserForms that take user-entered data and writes them to cells.
In the final UserForm in the sequence, data is written to a final cell.
In another cell, the data should concatenate (not using VBA, but as a standard formula in the cell using CONCAT).
Then, the VBA code should copy the concatenated cell to another one.
The problem is, all the VBA code from all the UserForms that have been used is executed, and then the CONCAT in the cell kicks in.
This results in the cell being copied before the data has been written to any cells and the CONCAT formula has returned its results.
This is the existing code:
Private Sub IssueComp_Done_Click()
If IssueComp_Yes.Value = True Then
Range("Answers!B23").Value = "I have verified the matter."
Else
Range("Answers!B23").Value = "I have not verified the matter"
End If
Range("Front!B7").Value = Range("Answers!C25").Value
Dim objLoop As Object
For Each objLoop In VBA.UserForms
If TypeOf objLoop Is UserForm Then Unload objLoop
Next objLoop
End Sub
This is the line that copies the concatenated cell:
Range("Front!B7").Value = Range("Answers!C25").Value
This is my CONCAT formula:
=IF(A52="DISP",CONCAT(C2,CHAR(10),CHAR(10),C7),IF(A52="NONDISP",CONCAT(C2,CHAR(10),CHAR(10),C20),"WAIT"))
When the code is run, cell Front!B7 displays WAIT.
This is how I knew it was copying the cell before values had been written and concatenated.
I replaced the source cell with the first cell that should contain data and it is empty when that line of VBA is executed.
This demonstrates nothing is written until the VBA code has executed to the end.
I found code to sleep, and to use the Application.CalculationState property.
It doesn't copy anything.
I tried rewriting the code to use variables instead of just cells, and again got nothing.
Is there a way of making sure cell Answers!C25 has executed the concatenation, i.e., no longer displays WAIT, and then execute the VBA code that copies the values?
ShowModalset to True or False? ShowModal propertyAnswers!C25. Now I checked the formula. It is not referencing the cellAnswers!B23. So how is the cell inC25supposed to update? FromAnswers!C2,Answers!C7orAnswers!C20?