簡體   English   中英

列中的值更改時更新特定的單元格

[英]Update a specific cell when a value changes in a column

我的任務是為一列數據創建一種方法,以更新底部單元格的最新條目。 更具體地說,在今年的每個月都輸入貸款組合金額,並且最新輸入也需要出現在該列的底部。 這是我最初想到的,但這不適用於底部之前的最后一個條目。

Private Sub Worksheet_Change(ByVal Target As Range)

xC = 0

yC = 7

If (Target.Column = 3) Then

Do

prevInt = currentInt

currentInt = Sheet1.Cells(yC, 3).Value

If (currentInt = 0) Then

Sheet1.Cells(19, 3).Value = prevInt

xC = 1

End If

yC = yC + 1

    Loop Until xC = 1

    End If

End Sub

我認為低於當前月份總數的單元格將始終為空白,除非是12月。 否則我不知道你怎么知道最新的:

Public Sub SetTotalCellValue()
Const portfolioColumn As Integer = 3
Const endRow As Integer = 14 'row of "total" cell

Dim sheet As Worksheet
Dim rowCount As Integer
Dim val As Object

rowCount = 2 'start at January, skip header row

'Set sheet = some sheet

'find last empty cell
For a = 1 To endRow
If sheet.Cells(a, portfolioColumn).Value = Empty Then
   sheet.Cells(endRow, portfolioColumn).Value = sheet.Cells(a - 1, portfolioColumn).Value
Exit For
ElseIf a = endRow - 1 Then
  sheet.Cells(endRow, portfolioColumn).Value = sheet.Cells(a, portfolioColumn).Value
Exit For
End If

Next a

End Sub

暫無
暫無

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

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