The task to do :
Col A Col D
100 4
101 2
102 4
105 2
100 1
101 2
102 3
1055 1
After my code is run, I need for my spreadsheet to look like this
Col A Col D
100 5
101 4
102 7
105 2
And there was one guy post his solution code below :
Sub Test()
Dim Sh As Worksheet
Dim LastRow As Long
Dim Rng As Range
Set Sh = Worksheets(1)
Sh.Columns(5).Insert
LastRow = Sh.Range("A65536").End(xlUp).Row
With Sh.Range("A1:A" & LastRow).Offset(0, 4)
.FormulaR1C1 = "=IF(COUNTIF(R1C[-4]:RC[-4],RC[-4])>1,"""",SUMIF(R1C[-4]:R[" & LastRow & "]C[-4],RC[-4],R1C[-1]:R[" & LastRow & "]C[-1]))"
.Value = .Value
End With
Sh.Columns(4).Delete
Sh.Rows(1).Insert
Set Rng = Sh.Range("D1:D" & LastRow + 1)
With Rng
.AutoFilter Field:=1, Criteria1:="="
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
End Sub
Now , based on this code, i have too much confusions:
1: why did he insert column 5?
2, how to understand the COUNTIF systax ?? What is [-1] etc
3,what did he mean for deleting column5, and insert Row (1)??
4,why did he use autofilter?
i am sorry for my confusions, this code is realy awsome, just want to know how does it work,,, because i am a noob now....
Many thanks for any help !!!!!!!!!!!!
Bookmarks