0
我正在嘗試爲電子表格創建邊框並對兩個值進行比較。要做到這一點,我必須增加我的範圍內的行,但我使用的公式不會增加。VBA 2010增量範圍行數不會增加
Set ws = Sheets(strSheetName)
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
Stop
'Create borders
For Each c In Range("A1:A" & lRow)
If Trim(c.Value) = PracticeName Then First = "A" & c.Row
If Trim(c.Value) = "SubTotal" Then SubTotal = "B" & c.Row
If Trim(c.Value) = "" Then
Set Rng = Sheets(strSheetName).Range(First & ":" & SubTotal)
Call SetRangeBorder(Rng)
End If
If Trim(c.Value) = PracticeName Then FirstDataRow = "B" & c.Row + 2
If Trim(c.Value) = "IDX" Then LastDataRow = "B" & c.Row
Stop
If LastDataRow <> "" And SubTotal <> "" Then
If Trim(c.Value) = "SubTotal" Then Range(SubTotal).Formula = "=SUM("
& FirstDataRow & ":" & LastDataRow & ")"
'Check if Values are equal
Stop
compare1 = Range(SubTotal)
FinalRow = "B" & c.Row + 1
compare2 = Range(FinalRow)
'If equal set color to green
If compare1 = compare2 Then Range(FinalRow).Interior.ColorIndex = 4
'If not equal set color to red
If compare1 <> compare2 Then Range(FinalRow).Interior.ColorIndex = 3
Range("A" & c.Row) = Range("A" & c.Row).Offset(3, 0)
Stop
End If
Next
此外,請確保在Range(「A1:A」&lRow)'之前添加工作表,以確保您在正確的位置運行該工作表...我假設它是'ws.Range(「A1:A 「&lRow)'? – BruceWayne
你是怎麼聲明'c'(數據類型)的? – danieltakeshi