簡體   English   中英

每次單擊按鈕時增加 excel 中的行值

[英]Increment Row value in excel on each button click

在 excel 宏中,每次單擊按鈕時我都需要增加行。 應該從數據表中讀取的下一個值函數的排序。 此外,此值需要返回到不同工作表中的單元格。 這是我擁有的代碼,如何增加每次點擊的價值。 我嘗試了 Offset() 但我希望按鈕記住我以前的位置。 For 循環中的某些東西可能

Sub Button6_Click()

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

End Sub

我不確定我是否正確理解了您的問題,但您似乎希望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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM