我想設計一個表單,從兩個特定單元格中按比例減去一個數字(已在用戶表單文本框中輸入),并暫時查看結果而不實際/永久更改這些單元格值。(例如,從當前值分別為 353 和 158 的兩個單元格中按比例減去數字 54)
uj5u.com熱心網友回復:
這并不完全是“優雅”,但我想您可以使用自定義數字格式讓單元格顯示與其實際包含的值不同的值。
Sub run_demo() 'temporarily formats A1 to show custom message
showValue ActiveSheet.Range("A1"), "Please wait!"
End Sub
Sub showValue(myCell As Range, tmpValue As String)
Dim origFormat As String
origFormat = myCell.NumberFormat 'store original cell format
myCell.NumberFormat = """" & tmpValue & """" 'display custom message
'...now do whatever u gotta do:
Application.CalculateFull 'for example you could force recalculation
pause 3 '(pausing 3 seconds, just for demo)
myCell.NumberFormat = origFormat 'replace original cell format
End Sub
Sub pause(sec As Single)
Dim t As Single: t = Timer 'get current time
Do: DoEvents: Loop While Timer < t 3 'wait til [sec] secs elapsed
End Sub
...但我想如果您要為此煩惱,您也可以只存盤實際的單元格值(除非它與作業表重新計算相關,在這種情況下,此方法將起作用,因為單元格的格式不會影響計算 - 無論如何,理論上。)
我不清楚你的目標(你的問題有點含糊,沒有你嘗試過的任何例子)但無論如何,我不禁覺得可能有更好的方法來做到這一點。(我有時發現“退后一步”,重新分析你的目標,并從不同的角度解決它是有幫助的。)??
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/384883.html
