Reputation: 11
I have a Bubble chart that I am trying to add "motion" to by having a macro update the table and subsequently the chart. I have a cell that I use as the "offset" which is used by my data table to get the data. I have a button that runs a VBA macro that updates this "offset" cell for each month in my data, which updates the data table when the offset updates.
When I alter the offset cell manually, both the table and chart update. However, when I click the button and run the VBA macro, only the table updates, NOT the graph.
I have looked researched possible solution, including those items located here on Stack Overflow, and have tried the following:
-DoEvents
-Applications.Calculate
-ActiveWorkbook.RefreshAll
-Chart.Refresh
-setting the Application.ScreenUpdating to false and back to true
Here is my VBA code:
Sub Button7_Click()
Dim i As Integer
For i = 0 To 9:
Range("P1").Value = i
Application.Calculate
Application.Wait DateAdd("s", 1, Now)
Next
Range("P1").Value = 0
End Sub
It shouldn't be this hard to update a graph when the table updates via VBA.
Upvotes: 1
Views: 6923
Reputation: 11
I've had this problem. Seems related with Excel 2016.
Sub CommButton1_Click()
i = Cells(4, 24)
start = Cells(4, 22)
rango = Cells(4, 23) + start
Do Until start > rango
Sleep (20)
Cells(4, 25).Value = start
start = start + i
DoEvents
DoEvents
Loop
End Sub
The soultion seems to be to add another DoEvents. I've tried in Excel 2016 and it worked, but with a big time delay.
Upvotes: 1
Reputation: 1874
Based on my test, the following code works on my side:
Sub Button7_Click()
Dim i As Integer
Dim sheet As Worksheet
Set sheet = Worksheets("Sheet10")
ActiveSheet.EnableCalculation = True
Application.ScreenUpdating = True
For i = 1 To 9
'sheet.Range("A1") = CStr(i)
sheet.Cells(i, 1) = CStr(i)
'Application.Wait (DateAdd("s", 1, Now))
Next
sheet.UsedRange.Calculate
ActiveSheet.EnableCalculation = False
Range("A1").Value = 0
End Sub
Upvotes: 0