【发布时间】:2016-01-09 20:34:30
【问题描述】:
我在 DEMAND 行中有值,在 COLLECTION 行中有值,现在我想要 BALANCE = DEMAND-COLLECTION,一个条目有两次收集,因此根据收集的发生情况应该出现余额。你能告诉我那个宏代码吗?
我有 D2:S2 的 DEMAND 值 D1:S1 COLLECTION 值,余额应该在下一行。
在得到解决方案后,我来到了这一步 Insert row base on specific text and its occurrence
我正在使用以下代码
Sub try()
Dim c As Range
Dim lRow As Long
lRow = 1
Dim lRowLast As Long
Dim bFound As Boolean
With ActiveSheet
lRowLast = .Cells(.Rows.Count, 1).End(xlUp).Row
Do
Set c = .Range("A" & lRow)
If c.Value Like "*COLLECTION*" Then
bFound = True
ElseIf bFound Then
bFound = False
If c.Value <> "BALANCE" Then
c.EntireRow.Insert
lRowLast = lRowLast + 1
c.Offset(-1, 0).Value = "BALANCE"
c.Offset(-1, 0).Font.Color = RGB(0, 0, 0)
End If
End If
lRow = lRow + 1
Loop While lRow <= lRowLast + 1
End With
End Sub
【问题讨论】: