Need help, If statement not providing desired result. Values in the comparing cells are the same but the if argument works half the time. Code provided below
Sub autofilter1()
For b = 1 To 4
' Last row of unique values - Unique Tab
lr = Sheets("Unique").Cells(Rows.Count, b).End(xlUp).Row
'Tabs = c
ws_count = ActiveWorkbook.Worksheets.Count
For c = 2 To ws_count
'Last row of column A
lr1 = Sheets(c).Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lr
'Execution of auto filter program
Sheets(c).Range("A1:A" & lr1).autofilter Field:=1, Criteria1:=Sheets("Unique").Range("A" & i)
'Last row of Filtered visible cells
lr2 = Sheets(c).Cells(Rows.Count, 4).End(xlUp).Row
'Below line selects entire range of visible cells
'Sheets("Assets").Range("D2:D" & lr2).SpecialCells(xlCellTypeVisible).Select
'Selection of Cell to identify aggregate address 1) Range definition, 2) sub-class aggregate cell identifier
With Sheets(c).autofilter.Range
Range("D" & .Offset(1, 0).SpecialCells(xlCellTypeVisible)(1).Row).Select
End With
'Dynamic Sum function home
Selection.Offset(0, 1).Select
'First cell below primary (only in case of multiple sub accounts, else primary is account)
SS = Selection.Offset(1, -1).Address
'Final cell of dynamic autofilter range
SE = ("D" & lr2)
Rng = Sheets(c).Range(SS & " : " & SE).SpecialCells(xlCellTypeVisible)
ActiveCell = Application.WorksheetFunction.Sum(Rng)
If ActiveCell.Value = ActiveCell.Offset(0, -1).Value Then
ActiveCell.Offset(0, 1) = "True"
ActiveCell.Offset(0, 1).Font.Bold = True
ActiveCell.Offset(0, 1).Interior.Color = 5296274
Else
ActiveCell.Offset(0, 1) = "False"
ActiveCell.Offset(0, 1).Font.Bold = True
ActiveCell.Offset(0, 1).Interior.Color = 255
End If
Next i
Next c
Next b
End Sub