你在找什麼是一個宏,而不是一個公式。我假設你在COLUMNS而不是ROWS上執行此操作。 EG:A1和B1,而不是A1和A2。
有什麼區別?
宏:可以在事件上觸發一次。
公式:給定一個輸入,它會不斷重新評估結果。
步驟1)按Alt + F11,這將打開VBA中的代碼編輯器。
步驟2)複製和粘貼下面的代碼到您的「片」您的公式駐留英寸
步驟3)保存工作簿作爲一個啓用宏的電子表格。 (XLSM)。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
If (Target.Columns.Count = 1 And Target.Column = 2 And Target.Rows.Count = 1) Then
'Check every row, currently this will get executed once
For Each cell In Target.Cells
'Make sure the value is a number
If (IsNumeric(cell.Value)) Then
'Make sure the value is greater than 0
If (cell.Value > 0) Then
'Check to make sure the date column is empty, so it only ever gets written once
'Note: You can remove the if statement below, if you want it to get re-evaluated every time you make a change
If (Target.Worksheet.Cells(cell.row, 1).Value = "") Then
'Using the current modified row, set column 1 to Today
'Note: Now() is the same as Today in VBA
Target.Worksheet.Cells(cell.row, 1).Value = Now()
End If
End If
End If
Next cell
End If
End Sub
注意:此宏,如果您一次修改一行只被執行,你可以改變它通過去除第一的「Target.Rows.Count = 1」的一部分,如果在多個小區上工作「 '聲明。
注2:如果希望在對列2進行更改時重新評估日期,可以刪除最後嵌套的'if'語句。(又名列B,在VBA列中通過數字引用,而不是字母)。注意3:如果你真的需要它通過行來工作,試着用調試器來逐步瞭解這個宏,然後重新構建它。關閉行而不是列。
您必須使用VBA。 –
你將不得不使用VBA。正如你注意到的那樣,在任何地方使用'= Today()'都會更新到文件打開的那一天。使用VBA,您可以有一個等待列A更改的宏,然後獲取結果並將值粘貼到其上。嘗試在宏記錄器中做這個(做你的公式,複製和粘貼值),併發回任何想法。 – BruceWayne
或*觀察* A2大於'0'並且在A1 Ctrl +';'中。 – pnuts