Discussion Re: copy previous value of variable cell to another cell location in same spreadsheet in Excel
https://techcommunity.microsoft.com/t5/excel/copy-previous-value-of-variable-cell-to-another-cell-location-in/m-p/2769257#M114677
<P><LI-USER uid="127945"></LI-USER></P><P>Thank you for the response</P><P>In the line 21 of the solver, is it possible to put something like this:</P><P> </P><P> </P><P> </P><LI-CODE lang="visual-basic">If -0.01 < Round(Range("N" & I).Value, 3) < 0.01 Then</LI-CODE><P> </P><P> </P><P> </P><P>Essentially, What I want to mention is that, the 'If statement' I'm relaxing between range -0.01 to 0.01, and not strictly as 0</P><P>That means, if the cell shows value -0.009 then also the value in cell O38 will get copied to new spot in T column.</P><P>Something like that is it possible?</P><P>I'm beginner in VBA and trying to understand...</P>Tue, 21 Sep 2021 03:13:44 GMTAshKot12021-09-21T03:13:44Zcopy previous value of variable cell to another cell location in same spreadsheet
https://techcommunity.microsoft.com/t5/excel/copy-previous-value-of-variable-cell-to-another-cell-location-in/m-p/2765993#M114571
<P>Hello All,</P><P>Based upon resources found on the internet (various forums, websites, communities) I did able to create one excel solver macro which automates the solver calculations. Each solver calculation involves setting target cell to zero by changing variable cell. both are single cell entities.</P><P>And like that, it runs solver function 11 times and each time the variable cell changes.</P><P>For example, during the solver calculations, In the first calculation target cell is N7, and its changed to 0 by changing variable cell O38, now the first calculation produced one value in O38 cell.</P><P>Solver immediately starts calculating second calculation, and now its target cell is N8 while the variable cell is O38, and the cell is holding value generated after first calculation (it is the same cell from first calculation, with result from calculation 1). Now, second calculation completed, and O38 cell holds new value, while the previous value is erased.</P><P>What I did is I added spreadsheet code by right clicking the spreadsheet, the code basically does copy previous value in the cell to new location, but its not working with VBA macro. That means whatever automated calculations are performed after that the spreadsheet code copies the previous value to new location.</P><P>I did not able to do it correctly.</P><P>I have attached excel file involving all the code</P><P><U><STRONG>What I have in my mind is,</STRONG></U></P><P><U><STRONG>How can create VBA macro, which is:</STRONG></U></P><P><U><STRONG>1. Performing first calculation in N7 with whatever value in cell 'O38'</STRONG></U></P><P><U><STRONG>2. Find out value of 0 in range of cells 'N7:N16' or just check whether 'N7' become 0</STRONG></U></P><P><U><STRONG>3. If value is 0 in any cell in range of cells 'N7:N16' or just cell 'N7'</STRONG></U></P><P><U><STRONG>4. then copy value in cell O38 to another location lets say cell 'T3'</STRONG></U></P><P><U><STRONG>5. takes pause 1 to 3 seconds</STRONG></U></P><P><U><STRONG>5. Start performing second calculation with N8</STRONG></U></P><P><U><STRONG>6. repeat all the tasks 1 to 5</STRONG></U></P><P><U><STRONG>like that complete calculations for range of cells 'N7:N16'.</STRONG></U></P><P><U><STRONG>At the end of macro I shall have multiple values captured from cell O38 and stored in multiple cells in T column one after another.</STRONG></U></P><P><U><STRONG>Please help me, I'm in desperate need, or assist me with the resources. from which I can develop something.</STRONG></U></P><P>Thank you!</P><P>Regards,</P><P>Ash.K </P>Mon, 20 Sep 2021 04:08:43 GMThttps://techcommunity.microsoft.com/t5/excel/copy-previous-value-of-variable-cell-to-another-cell-location-in/m-p/2765993#M114571AshKot12021-09-20T04:08:43ZRe: copy previous value of variable cell to another cell location in same spreadsheet
https://techcommunity.microsoft.com/t5/excel/copy-previous-value-of-variable-cell-to-another-cell-location-in/m-p/2766574#M114587
<P><LI-USER uid="1160067"></LI-USER> </P>
<P>Try this:</P>
<LI-CODE lang="visual-basic">Dim I As Long
' SolverAutomation macro
Sub SolverAutomation1()
Application.EnableEvents = False
' Clear the output range
Range("T6:T17").ClearContents
' Initialize I
I = 6
' Perform solver
DoIt
Application.EnableEvents = True
End Sub
Sub DoIt(Optional Dummy)
' Solver steps
SolverReset
SolverOk SetCell:="$N$" & I, MaxMinVal:=3, ValueOf:=0, ByChange:="$O$38", Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
' Check whether cell in column N is near enough to 0
If Round(Range("N" & I).Value, 3) = 0 Then
' If so, copy O38 to column T
Range("T" & I).Value = Range("O38").Value
End If
' Increment I
I = I + 1
' Stop if I > 17
If I <= 17 Then
' Call DoIt with a short delay
Application.OnTime Now + TimeSerial(0, 0, 2), "DoIt"
End If
End Sub</LI-CODE>Mon, 20 Sep 2021 09:39:07 GMThttps://techcommunity.microsoft.com/t5/excel/copy-previous-value-of-variable-cell-to-another-cell-location-in/m-p/2766574#M114587Hans Vogelaar2021-09-20T09:39:07ZRe: copy previous value of variable cell to another cell location in same spreadsheet
https://techcommunity.microsoft.com/t5/excel/copy-previous-value-of-variable-cell-to-another-cell-location-in/m-p/2769257#M114677
<P><LI-USER uid="127945"></LI-USER></P><P>Thank you for the response</P><P>In the line 21 of the solver, is it possible to put something like this:</P><P> </P><P> </P><P> </P><LI-CODE lang="visual-basic">If -0.01 < Round(Range("N" & I).Value, 3) < 0.01 Then</LI-CODE><P> </P><P> </P><P> </P><P>Essentially, What I want to mention is that, the 'If statement' I'm relaxing between range -0.01 to 0.01, and not strictly as 0</P><P>That means, if the cell shows value -0.009 then also the value in cell O38 will get copied to new spot in T column.</P><P>Something like that is it possible?</P><P>I'm beginner in VBA and trying to understand...</P>Tue, 21 Sep 2021 03:13:44 GMThttps://techcommunity.microsoft.com/t5/excel/copy-previous-value-of-variable-cell-to-another-cell-location-in/m-p/2769257#M114677AshKot12021-09-21T03:13:44ZRe: copy previous value of variable cell to another cell location in same spreadsheet
https://techcommunity.microsoft.com/t5/excel/copy-previous-value-of-variable-cell-to-another-cell-location-in/m-p/2769884#M114728
<P><LI-USER uid="1160067"></LI-USER> </P>
<P>Change the line</P>
<LI-CODE lang="visual-basic">If Round(Range("N" & I).Value, 3) = 0 Then</LI-CODE>
<P>to</P>
<LI-CODE lang="visual-basic">If Abs(Range("N" & I).Value) < 0.01 Then</LI-CODE>Tue, 21 Sep 2021 10:13:00 GMThttps://techcommunity.microsoft.com/t5/excel/copy-previous-value-of-variable-cell-to-another-cell-location-in/m-p/2769884#M114728Hans Vogelaar2021-09-21T10:13:00Z