Code:
' 31 July and 6 August Low
Sub SingleReqList()
Dim StTime As Long: Let StTime = Timer
Dim wsIPs As Worksheet, wsReqs As Worksheet, wsAllReqs As Worksheet, wsAllIPs As Worksheet
Set wsIPs = ThisWorkbook.Worksheets("IPs"): Set wsReqs = ThisWorkbook.Worksheets("Requests"): Set wsAllReqs = ThisWorkbook.Worksheets("AllRequests"): Set wsAllIPs = ThisWorkbook.Worksheets("AllIPs")
Dim Lr As Long
' Let Lr = wsAllReqs.Range("D" & wsAllReqs.Rows.Count & "").End(xlUp).Row
Let Lr = wsAllReqs.Range("J" & wsAllReqs.Rows.Count & "").End(xlUp).Row
Dim rngReqs As Range
' Set rngReqs = wsAllReqs.Range("D2:F" & Lr & "")
Set rngReqs = wsAllReqs.Range("J2:L" & Lr & "")
Dim Cnt As Long
For Cnt = 2 To Lr Step 1
' If Len(wsAllReqs.Range("E" & Cnt & "").Value2) > 255 Then GoTo NxtCnt
' If wsAllReqs.Range("E" & Cnt & "") = "" Or wsAllReqs.Range("E" & Cnt & "") = Empty Or Cnt = Lr Then GoTo ExtSb ' This should happen as we are deleting cells so eventually we will reach the end of the shortened range ( It gets shortened every time a row is deleted. ) If we are doung a second take nd nothing happens we will reach Lr but the search range becomes that with Lr in it which causes a glitch
If Len(wsAllReqs.Range("K" & Cnt & "").Value2) > 255 Then GoTo NxtCnt
If wsAllReqs.Range("K" & Cnt & "") = "" Or wsAllReqs.Range("K" & Cnt & "") = Empty Or Cnt = Lr Then GoTo ExtSb ' This should happen as we are deleting cells so eventually we will reach the end of the shortened range ( It gets shortened every time a row is deleted. ) If we are doung a second take nd nothing happens we will reach Lr but the search range becomes that with Lr in it which causes a glitch
Dim rngFnd As Range, rngSrch As Range
' Set rngSrch = wsAllReqs.Range("E" & Cnt + 1 & ":E" & Lr & "") ' I dont want to be searching the range including the value i am looking for, or I will find it as last, (after getting to the end and then starting again), and delete the fucker
' Set rngFnd = rngSrch.Find(What:=wsAllReqs.Range("E" & Cnt & "").Value2, After:=wsAllReqs.Range("E" & Cnt + 1 & ""), LookIn:=xlValues, Lookat:=xlWhole, Searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=True)
Set rngSrch = wsAllReqs.Range("K" & Cnt + 1 & ":K" & Lr & "") ' I dont want to be searching the range including the value i am looking for, or I will find it as last, (after getting to the end and then starting again), and delete the fucker
Set rngFnd = rngSrch.Find(What:=wsAllReqs.Range("K" & Cnt & "").Value2, After:=wsAllReqs.Range("K" & Cnt + 1 & ""), LookIn:=xlValues, Lookat:=xlWhole, Searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=True)
' Set rngFnd = rngSrch.Find(What:=wsAllReqs.Range("E" & Cnt & "").Value2, After:=wsAllReqs.Range("E" & Cnt + 1 & ""), LookIn:=xlValues, Lookat:=xlPart, Searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=True)
Do While Not rngFnd Is Nothing
' Let wsAllReqs.Range("D" & Cnt & "") = wsAllReqs.Range("D" & Cnt & "").Value + rngFnd.Offset(0, -1).Value ' Hits
' Let wsAllReqs.Range("F" & Cnt & "") = wsAllReqs.Range("F" & Cnt & "").Value & vbCr & vbLf & " " & rngFnd.Offset(0, 1).Value ' IP addresses making the hits/ requests
' Let wsAllReqs.Range("F" & Cnt & "").WrapText = False
Let wsAllReqs.Range("J" & Cnt & "") = wsAllReqs.Range("J" & Cnt & "").Value + rngFnd.Offset(0, -1).Value ' Hits
Let wsAllReqs.Range("L" & Cnt & "") = wsAllReqs.Range("L" & Cnt & "").Value & vbCr & vbLf & " " & rngFnd.Offset(0, 1).Value ' IP addresses making the hits/ requests
Let wsAllReqs.Range("L" & Cnt & "").WrapText = False
rngFnd.Offset(0, -1).Resize(1, 3).Delete Shift:=xlUp ' Delete duplicate row after adding hits and ip addresses
' Set rngFnd = rngSrch.Find(What:=wsAllReqs.Range("E" & Cnt & "").Value2, After:=wsAllReqs.Range("E" & Cnt + 1 & ""), LookIn:=xlValues, Lookat:=xlWhole, Searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=True)
Set rngFnd = rngSrch.Find(What:=wsAllReqs.Range("K" & Cnt & "").Value2, After:=wsAllReqs.Range("K" & Cnt + 1 & ""), LookIn:=xlValues, Lookat:=xlWhole, Searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=True)
' Set rngFnd = rngSrch.Find(What:=wsAllReqs.Range("E" & Cnt & "").Value2, After:=wsAllReqs.Range("E" & Cnt + 1 & ""), LookIn:=xlValues, Lookat:=xlPart, Searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=True)
Loop ' While Not rngFnd = Nothing
NxtCnt:
Debug.Print Cnt
Next Cnt
ExtSb:
Debug.Print Int((Timer - StTime) / 60) & "min " & Format(Now, "ddd dd mmm yyyy hh:nn")
End Sub ' 4min Do 25 Sep 2025 22:29
Sub SingleReqListDics()
Dim StTime As Long: Let StTime = Timer
Dim wsIPs As Worksheet, wsReqs As Worksheet, wsAllReqs As Worksheet, wsAllIPs As Worksheet
Set wsIPs = ThisWorkbook.Worksheets("IPs"): Set wsReqs = ThisWorkbook.Worksheets("Requests"): Set wsAllReqs = ThisWorkbook.Worksheets("AllRequests"): Set wsAllIPs = ThisWorkbook.Worksheets("AllIPs")
Dim Lr As Long
' Let Lr = wsAllReqs.Range("D" & wsAllReqs.Rows.Count & "").End(xlUp).Row
Let Lr = wsAllReqs.Range("J" & wsAllReqs.Rows.Count & "").End(xlUp).Row
Dim rngReqs As Range
' Set rngReqs = wsAllReqs.Range("D2:F" & Lr & "")
Set rngReqs = wsAllReqs.Range("J2:L" & Lr & "")
Dim DicVw As Object, DicIP As Object
Set DicVw = CreateObject("Scripting.Dictionary"): Set DicIP = CreateObject("Scripting.Dictionary")
Dim Cnt As Long
Rem Make Dics Item or adds to it
For Cnt = 2 To Lr Step 1
If Not DicVw.exists(wsAllReqs.Range("K" & Cnt & "").Value) Then
DicVw.Add Key:=wsAllReqs.Range("K" & Cnt & "").Value, Item:=wsAllReqs.Range("J" & Cnt & "").Value
DicIP.Add Key:=wsAllReqs.Range("K" & Cnt & "").Value, Item:=wsAllReqs.Range("L" & Cnt & "").Value
Else ' Add the infomation of view count and IPAddresses
Let DicVw(wsAllReqs.Range("K" & Cnt & "").Value) = DicVw(wsAllReqs.Range("K" & Cnt & "").Value) + wsAllReqs.Range("J" & Cnt & "").Value
Let DicIP(wsAllReqs.Range("K" & Cnt & "").Value) = DicIP(wsAllReqs.Range("K" & Cnt & "").Value) & vbCr & vbLf & " " & wsAllReqs.Range("L" & Cnt & "").Value
End If
NxtCnt:
'Debug.Print Cnt
Next Cnt
Rem output
Dim arrReqVw() As Variant, arrVw() As Variant, arrIP() As Variant, arrReqIP() As Variant
Let arrReqVw() = DicVw.keys(): arrVw() = DicVw.items(): arrIP() = DicIP.items(): arrReqIP() = DicIP.keys()
Let wsAllReqs.Range("N2").Resize(UBound(arrReqVw()) + 1, 1) = Application.Transpose(arrReqVw())
'Let wsAllReqs.Range("P2").Resize(UBound(arrReqVw()) + 1, 1) = Application.Transpose(arrReqVw())
Let wsAllReqs.Range("M2").Resize(UBound(arrVw()) + 1, 1) = Application.Transpose(arrVw())
Let wsAllReqs.Range("M2").Resize(UBound(arrVw()) + 1, 1) = Application.Index(arrVw(), 1, Evaluate("Row(1:" & UBound(arrVw()) + 1 & ")"))
Dim strIPs As String, arrIPsstr() As String ' Problem with string longer than 255 characters in a Transpose (or Index) when variant arrays have any element with a string over 255 characters
Let strIPs = Join(arrIP(), "|") ' https://stackoverflow.com/questions/35395789/excel-vba-need-workaround-for-255-transpose-character-limit-when-returning-vari/79775234#79775234
Let arrIPsstr() = Split(strIPs, "|") ' https://stackoverflow.com/a/79775234/4031841
Let wsAllReqs.Range("O2").Resize(UBound(arrIPsstr()) + 1, 1) = Application.Index(arrIPsstr(), 1, Evaluate("Row(1:" & UBound(arrIPsstr()) + 1 & ")"))
Let wsAllReqs.Cells.WrapText = False
ExtSb:
Debug.Print Int((Timer - StTime) / 60) & "min " & Format(Now, "ddd dd mmm yyyy hh:nn")
End Sub ' 0min Do 25 Sep 2025 22:19
Bookmarks