怎么在excel中随系统时间动态的改变单元格位置
已建立一个表格,在第一行插入一个已知的过去时间,然后根据系统时间算出要向下插入多少行,并插入每行加一的日期,希望每次打开都会自动的更新,怎么弄?
求指教
[解决办法]
你看看能否满足你的要求
Sub InsertRow()
Dim NewDate As Long, OldDate As Long
NewDate = Date
If Sheets(1).Cells(1, 1) = "" Or Val(Sheets(1).Cells(1, 1)) = 0 Then
Exit Sub
End If
OldDate = DateValue(Sheets(1).Cells(1, 1))
If OldDate = 0 Or OldDate >= NewDate Or NewDate - OldDate > 1000 Then
Exit Sub
End If
Application.EnableEvents = False
Dim Temp As Long
For Temp = OldDate + 1 To NewDate
Sheets(1).Rows(1).Insert Shift:=xlDown
Sheets(1).Cells(1, 1) = Temp
Sheets(1).Cells(1, 1).NumberFormatLocal = "YYYY-M-D"
Next Temp
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect([A1:A1], Target) Is Nothing Then
InsertRow
End If
End Sub
Private Sub Workbook_Open()
InsertRow
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect([A1:A1], Target) Is Nothing Then
InsertRow
End If
End Sub
Public Sub InsertRow()
Dim NewDate As Long, OldDate As Long
NewDate = Date
If Sheets(1).Cells(1, 1) = "" Or Val(Sheets(1).Cells(1, 1)) = 0 Then
Exit Sub
End If
OldDate = DateValue(Sheets(1).Cells(1, 1))
If OldDate = 0 Or OldDate >= NewDate Or NewDate - OldDate > 1000 Then
Exit Sub
End If
Application.EnableEvents = False
Dim Temp As Long
For Temp = OldDate + 1 To NewDate
Sheets(1).Rows(1).Insert Shift:=xlDown
Sheets(1).Cells(1, 1) = Temp
Sheets(1).Cells(1, 1).NumberFormatLocal = "YYYY-M-D"
Next Temp
Application.EnableEvents = True
End Sub
Private Sub Workbook_Open()
Sheets(1).InsertRow
End Sub