|
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastRow As Long
Dim accountingFormat As String
' 设置会计专用格式字符串(你可以根据需要修改这个格式)
accountingFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
' 检查更改是否发生在E列或F列以及是否在前三行之后
If Not Intersect(Target, Me.Range("E4:F" & Me.Rows.Count)) Is Nothing Then
' 查找E列和F列的最后一行
lastRow = Me.Cells(Me.Rows.Count, "E").End(xlUp).row
' 如果更改发生在最后一行之前,并且不在前三行,则重新计算G列对应行的值
If Target.row <= lastRow And Target.row > 3 Then
Me.Cells(Target.row, "G").Value = Me.Cells(Target.row, "E").Value * Me.Cells(Target.row, "F").Value
' 将G列的格式设置为会计专用格式
Me.Cells(Target.row, "G").NumberFormat = accountingFormat
' 也可以将E列和F列的格式设置为会计专用格式(如果需要)
Me.Cells(Target.row, "E").NumberFormat = accountingFormat
Me.Cells(Target.row, "F").NumberFormat = accountingFormat
End If
End If
End Sub
|
|