goin2daship
New Member
- Joined
- Mar 4, 2018
- Messages
- 3
I have a bunch of IP Addresses in Column C that are in consecutive order containing duplicates. In Column D I have a text value that could be 1 of 4 items (Critical, High, Medium, Low). I need to delete the Duplicate IPs and Sum the occurrences of the criteria in another Worksheet to the same Row. I used to different button to do this. The first to analyze Column C and transfer copy IPs to WS4 minus duplicate. The second command I created a loop to attempt to sum up each Criteria (Critical and High are same) and place in same row as number of IP occurrences. Code is below (sheet's 3 is original data, sheet 4 should be output but the Loop is skipping lines and I don't know why).
Private Sub CommandButton1_Click()
a = Worksheets("Sheet3").Cells(Rows.Count, 3).End(xlUp).Row
cnt = 2
For i = 2 To a
If Worksheets("Sheet3").Cells(i, 3).Value <> Worksheets("Sheet3").Cells(i - 1, 3).Value Then
Worksheets("Sheet3").Cells(i, 3).Copy
Worksheets("Sheet4").Activate
b = Worksheets("Sheet4").Cells(Rows.Count, 3).End(xlUp).Row
Worksheets("Sheet4").Cells(b + 1, 3).Select
ActiveSheet.Paste
Worksheets("Sheet3").Activate
ElseIf Worksheets("Sheet3").Cells(i, 3).Value = Worksheets("Sheet3").Cells(i - 1, 3).Value Then
End If
Next
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Sheet3").Cells(1, 1).Select
End Sub
Private Sub CommandButton2_Click()
C = Worksheets("Sheet3").Cells(Rows.Count, 3).End(xlUp).Row
Dim Low, Medium, High As Integer
Dim NextIP As Long
NextIP = 2
cnt = 2
For s = cnt To C
Do While Worksheets("Sheet3").Cells(s, 3).Value = Worksheets("Sheet3").Cells(cnt - 1, 3).Value
If Cells(cnt, 4).Value = "low" Then
Low = Low + 1
ElseIf Cells(cnt, 4).Value = "medium" Then
Medium = Medium + 1
ElseIf Cells(cnt, 4).Value = "high" Then
High = High + 1
ElseIf Cells(cnt, 4).Value = "critical" Then
High = High + 1
End If
cnt = cnt + 1
Loop
Worksheets("Sheet4").Cells(NextIP, 4).Value = Worksheets("Sheet4").Cells(NextIP, 4).Value + Low
Worksheets("Sheet4").Cells(NextIP, 5).Value = Worksheets("Sheet4").Cells(NextIP, 5).Value + Medium
Worksheets("Sheet4").Cells(NextIP, 6).Value = Worksheets("Sheet4").Cells(NextIP, 6).Value + High
NextIP = NextIP + 1
Low = 0
Medium = 0
High = 0
Next
End Sub
Private Sub CommandButton1_Click()
a = Worksheets("Sheet3").Cells(Rows.Count, 3).End(xlUp).Row
cnt = 2
For i = 2 To a
If Worksheets("Sheet3").Cells(i, 3).Value <> Worksheets("Sheet3").Cells(i - 1, 3).Value Then
Worksheets("Sheet3").Cells(i, 3).Copy
Worksheets("Sheet4").Activate
b = Worksheets("Sheet4").Cells(Rows.Count, 3).End(xlUp).Row
Worksheets("Sheet4").Cells(b + 1, 3).Select
ActiveSheet.Paste
Worksheets("Sheet3").Activate
ElseIf Worksheets("Sheet3").Cells(i, 3).Value = Worksheets("Sheet3").Cells(i - 1, 3).Value Then
End If
Next
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Sheet3").Cells(1, 1).Select
End Sub
Private Sub CommandButton2_Click()
C = Worksheets("Sheet3").Cells(Rows.Count, 3).End(xlUp).Row
Dim Low, Medium, High As Integer
Dim NextIP As Long
NextIP = 2
cnt = 2
For s = cnt To C
Do While Worksheets("Sheet3").Cells(s, 3).Value = Worksheets("Sheet3").Cells(cnt - 1, 3).Value
If Cells(cnt, 4).Value = "low" Then
Low = Low + 1
ElseIf Cells(cnt, 4).Value = "medium" Then
Medium = Medium + 1
ElseIf Cells(cnt, 4).Value = "high" Then
High = High + 1
ElseIf Cells(cnt, 4).Value = "critical" Then
High = High + 1
End If
cnt = cnt + 1
Loop
Worksheets("Sheet4").Cells(NextIP, 4).Value = Worksheets("Sheet4").Cells(NextIP, 4).Value + Low
Worksheets("Sheet4").Cells(NextIP, 5).Value = Worksheets("Sheet4").Cells(NextIP, 5).Value + Medium
Worksheets("Sheet4").Cells(NextIP, 6).Value = Worksheets("Sheet4").Cells(NextIP, 6).Value + High
NextIP = NextIP + 1
Low = 0
Medium = 0
High = 0
Next
End Sub