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

问题描述 投票:-2回答:1

您好我想知道是否可以每天在现有值中添加值。例如,我在excel电子表格中有一些车辆,我想每天添加特定值。每天的价值都是一样的。一辆车有150公里,明天将有200公里。我怎样才能让它每天自动更新?先感谢您!

excel
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.