1

我的任务是为一列数据创建一种方法来更新底部单元格的最新条目。更具体地说,输入今年每个月的贷款组合金额,并且最近的条目也需要出现在列的底部。这是我最初想出的,但这不适用于底部之前的最后一个条目。

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
4

1 回答 1

0

我假设当前月份总数下方的单元格将始终为空白,除非它是 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
于 2012-06-08T20:59:54.233 回答