如何每天在excel中自动添加值

时间:2019-02-19 08:27:46

标签: excel

您好,我想知道是否有可能每天都在现有值中添加值。例如,我在excel电子表格中有一些载具,我想每天添加特别值。这些值每天都相同。一辆汽车有150公里,明天将有200公里。我如何使其每天自动更新?预先谢谢你!

1 个答案:

答案 0 :(得分:0)

我将证明可以帮助您的代码示例:

Option Explicit

Sub test()

    Dim LastRow As Long, i As Long, KMS As Long, AdditionalValue As Long
    Dim Vehicle As String
    Dim stDate As Date

    With ThisWorkbook.Worksheets("Sheet1")

        LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

            For i = 2 To LastRow

                AdditionalValue = 50
                stDate = .Range("A" & i).Value
                Vehicle = .Range("B" & i).Value
                KMS = .Range("C" & i).Value

                Do Until stDate = Date

                    KMS = KMS + AdditionalValue
                    stDate = stDate + 1

                Loop

                .Range("D" & i).Value = KMS

            Next i

    End With

End Sub

结果:

enter image description here