【问题标题】:Increment Row value in excel on each button click每次单击按钮时在excel中增加行值
【发布时间】:2015-05-04 13:50:51
【问题描述】:

在 excel 宏中,每次单击按钮时我都需要增加行。应该从数据表中读取的下一个值函数的排序。此外,此值需要返回到不同工作表中的单元格。这是我拥有的代码,如何增加每次点击的价值。我尝试了 Offset() 但我希望按钮记住我以前的位置。 For 循环中的某些东西可能

Sub Button6_Click()

Cells(4, 6) = Sheets("Sheet4").Range("B:B").Value

End Sub

【问题讨论】:

    标签: excel vba row increment


    【解决方案1】:

    我不确定我是否正确理解了您的问题,但您似乎希望 Cells(4,6) 在每次点击时都等于 Sheet4 中某个单元格的值向下移动一行。如果是这种情况:

    Dim previousRow As Long '<-- global variable previousRow
    Sub Button6_Click()
        If previousRow = 0 Then 
            previousRow = 1 '<--starts at row 1
        Else
            previousRow = previousRow + 1 '<--increases of 1 each click
        End If
        Sheets("Sheet1").Cells(4,6) = Sheets("Sheet4").Cells(previousRow,6) '<-- it will be the value of the cell in the column 6 with a variable row
        'first click: Cells(1,6)
        'second click: Cells(2,6)
        'third click: Cells(3,6)
        'etc.
    End Sub
    

    【讨论】:

    • 嗨,Matteo 非常感谢。这正是我所需要的。该按钮工作正常。
    猜你喜欢
    • 2016-09-28
    • 1970-01-01
    • 1970-01-01
    • 2022-08-08
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    • 1970-01-01
    • 2021-09-26
    相关资源
    最近更新 更多