繁体   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