muraterguen
New Member
- Joined
- Jan 8, 2016
- Messages
- 25
Hello,
In my file:
A1 has =SUM(A3:A100000) as a formula. B1 and C1 do the same addition for their columns...
The formula in A2 is =A1 , so I format this cell as a display. Same for B2 and C2.
Starting from A3, A1 does the addition every time a new number is entered into the cells to the bottom. A2 takes the data from A1 and continues displaying by animating in increments of 0.01 until it reaches the new number. Of course, the same is true for columns B and C.
There is VBA code for this, which I will share below.
The problem is;
These 3 separate cells are not working at the same time. If A is working, B and C are waiting, B starts when A's work is finished, C starts when B is finished. Can the macro code I shared be edited so that all 3 display cells work at the same time?
Thanks in advance
(I got this code written in ChatGPT)
Private Const DISPLAY_CELL_A = "A2"
Private Const DISPLAY_CELL_B = "B2"
Private Const DISPLAY_CELL_C = "C2"
Private DisplayCellA As Double
Private DisplayCellB As Double
Private DisplayCellC As Double
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongLong)
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
DisplayCellA = Range(DISPLAY_CELL_A).Value
DisplayCellB = Range(DISPLAY_CELL_B).Value
DisplayCellC = Range(DISPLAY_CELL_C).Value
Call UpdateDisplayCellA
Call UpdateDisplayCellB
Call UpdateDisplayCellC
End Sub
Private Sub Worksheet_Calculate()
DisplayCellA = Range(DISPLAY_CELL_A).Value
DisplayCellB = Range(DISPLAY_CELL_B).Value
DisplayCellC = Range(DISPLAY_CELL_C).Value
Call UpdateDisplayCellA
Call UpdateDisplayCellB
Call UpdateDisplayCellC
End Sub
Private Sub UpdateDisplayCellA()
Dim A1 As Double
Dim SleepTime As Double
SleepTime = 100 ' Time to wait before updating the display cell in milliseconds
A1 = Range("A1").Value
Do While DisplayCellA < A1
DisplayCellA = DisplayCellA + 0.01
Range(DISPLAY_CELL_A).Value = DisplayCellA
If A1 <> Range("A1").Value Then
Exit Sub
End If
DoEvents ' Allows the user to cancel the operation by pressing Esc
Sleep SleepTime ' Pauses the macro for SleepTime milliseconds
Loop
Range(DISPLAY_CELL_A).Value = A1
End Sub
Private Sub UpdateDisplayCellB()
Dim B1 As Double
Dim SleepTime As Double
SleepTime = 100 ' Time to wait before updating the display cell in milliseconds
B1 = Range("B1").Value
Do While DisplayCellB < B1
DisplayCellB = DisplayCellB + 0.01
Range(DISPLAY_CELL_B).Value = DisplayCellB
If B1 <> Range("B1").Value Then
Exit Sub
End If
DoEvents ' Allows the user to cancel the operation by pressing Esc
Sleep SleepTime ' Pauses the macro for SleepTime milliseconds
Loop
Range(DISPLAY_CELL_B).Value = B1
End Sub
Private Sub UpdateDisplayCellC()
Dim C1 As Double
Dim SleepTime As Double
SleepTime = 100 ' Time to wait before updating the display cell in milliseconds
C1 = Range("C1").Value
Do While DisplayCellC < C1
DisplayCellC = DisplayCellC + 0.01
Range(DISPLAY_CELL_C).Value = DisplayCellC
If C1 <> Range("C1").Value Then
Exit Sub
End If
DoEvents ' Allows the user to cancel the operation by pressing Esc
Sleep SleepTime ' Pauses the macro for SleepTime milliseconds
Loop
Range(DISPLAY_CELL_C).Value = C1
End Sub
In my file:
A1 has =SUM(A3:A100000) as a formula. B1 and C1 do the same addition for their columns...
The formula in A2 is =A1 , so I format this cell as a display. Same for B2 and C2.
Starting from A3, A1 does the addition every time a new number is entered into the cells to the bottom. A2 takes the data from A1 and continues displaying by animating in increments of 0.01 until it reaches the new number. Of course, the same is true for columns B and C.
There is VBA code for this, which I will share below.
The problem is;
These 3 separate cells are not working at the same time. If A is working, B and C are waiting, B starts when A's work is finished, C starts when B is finished. Can the macro code I shared be edited so that all 3 display cells work at the same time?
Thanks in advance
(I got this code written in ChatGPT)
Private Const DISPLAY_CELL_A = "A2"
Private Const DISPLAY_CELL_B = "B2"
Private Const DISPLAY_CELL_C = "C2"
Private DisplayCellA As Double
Private DisplayCellB As Double
Private DisplayCellC As Double
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongLong)
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
DisplayCellA = Range(DISPLAY_CELL_A).Value
DisplayCellB = Range(DISPLAY_CELL_B).Value
DisplayCellC = Range(DISPLAY_CELL_C).Value
Call UpdateDisplayCellA
Call UpdateDisplayCellB
Call UpdateDisplayCellC
End Sub
Private Sub Worksheet_Calculate()
DisplayCellA = Range(DISPLAY_CELL_A).Value
DisplayCellB = Range(DISPLAY_CELL_B).Value
DisplayCellC = Range(DISPLAY_CELL_C).Value
Call UpdateDisplayCellA
Call UpdateDisplayCellB
Call UpdateDisplayCellC
End Sub
Private Sub UpdateDisplayCellA()
Dim A1 As Double
Dim SleepTime As Double
SleepTime = 100 ' Time to wait before updating the display cell in milliseconds
A1 = Range("A1").Value
Do While DisplayCellA < A1
DisplayCellA = DisplayCellA + 0.01
Range(DISPLAY_CELL_A).Value = DisplayCellA
If A1 <> Range("A1").Value Then
Exit Sub
End If
DoEvents ' Allows the user to cancel the operation by pressing Esc
Sleep SleepTime ' Pauses the macro for SleepTime milliseconds
Loop
Range(DISPLAY_CELL_A).Value = A1
End Sub
Private Sub UpdateDisplayCellB()
Dim B1 As Double
Dim SleepTime As Double
SleepTime = 100 ' Time to wait before updating the display cell in milliseconds
B1 = Range("B1").Value
Do While DisplayCellB < B1
DisplayCellB = DisplayCellB + 0.01
Range(DISPLAY_CELL_B).Value = DisplayCellB
If B1 <> Range("B1").Value Then
Exit Sub
End If
DoEvents ' Allows the user to cancel the operation by pressing Esc
Sleep SleepTime ' Pauses the macro for SleepTime milliseconds
Loop
Range(DISPLAY_CELL_B).Value = B1
End Sub
Private Sub UpdateDisplayCellC()
Dim C1 As Double
Dim SleepTime As Double
SleepTime = 100 ' Time to wait before updating the display cell in milliseconds
C1 = Range("C1").Value
Do While DisplayCellC < C1
DisplayCellC = DisplayCellC + 0.01
Range(DISPLAY_CELL_C).Value = DisplayCellC
If C1 <> Range("C1").Value Then
Exit Sub
End If
DoEvents ' Allows the user to cancel the operation by pressing Esc
Sleep SleepTime ' Pauses the macro for SleepTime milliseconds
Loop
Range(DISPLAY_CELL_C).Value = C1
End Sub