Board logo

標題: [發問] 如何將公式改成值 [打印本頁]

作者: 藍天麗池    時間: 2024-1-5 16:58     標題: 如何將公式改成值

Sub RecordPrice()
Dim WR As Long
Dim I As Byte

If IsError(Range("B2")) Or IsError(Range("C2")) Then Exit Sub


WR = Range("A1").End(xlDown).Row + 1
'ActiveWindow.ScrollRow = WR - 5 '只顯示最新幾筆資料
If (WR = 3) Or _
   (Range("D" & WR - 1) <> Range("D2")) Then '總量有異動時才記錄
   'For I = 1 To 13
      'Cells(WR, I) = Cells(2, I)
   'Next 'I
   Cells(WR, 1).Resize(, 4) = [A2:D2].Value
   Cells(WR, "E").Formula = "=RC[-3]-R[-1]C[-3]"
   Cells(WR, "F").Formula = "=RC[-3]-R[-1]C[-3]"
   
  
End If

'For I = 1 To 9
'   Cells(WR, I) = Cells(2, I)
'Next 'I
End Sub

請問版上前輩,我如果要將上述程式中Cells(WR, "E").Formula = "=RC[-3]-R[-1]C[-3]"跟   Cells(WR, "F").Formula = "=RC[-3]-R[-1]C[-3]",在執行完公式後在儲存格上面只顯示值,而不是公式,要如何修改呢?
作者: blacklmj    時間: 2024-1-9 15:01

大大, 這兩行改成如下, 請您看合不合用?

   With Cells(WR, "E")
   .Value = .Offset(0, -3) - .Offset(-1, -3)
   End With
   With Cells(WR, "F")
   .Value = .Offset(0, -3) - .Offset(-1, -3)
   End With
作者: 藍天麗池    時間: 2024-1-11 20:54

回復 2# blacklmj


    感謝前輩回復




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)