Hello everyone
I recently made the code below which reads the values inside certain columns and verifies if they are all on the same row and increments if the combination is the same as the one defined
But now i want to add another feature to it and im not sure how to go about doing it which is why i need help
Basically there is column G in my second sheet(same sheet that receives all the other values) that receives dates in the format "dd/mm/yyyy" and i would like it so that depending on the week number associated with said date the counter would be placed in a different row in sheet15.
for example lets say that there are only these 5 rows filed in the columns i defined and these are the values present in that sheet :
i would want there to be 2 counters,1 for the row with : 1, 2, 3, 3/2/0, 28/09/2023 and 1, 2, 3, 3/1/0, 29/09/2023 and another counter for 1, 2, 3, 3/1/0, 05/06/2023
the first counter would have the number 2 being displayed because 2 rows have the correct combination and they share the same weeknumber associated with their dates and the other counter would have 1 because there's only one row present with the correct combination of values that has the same weeknumber
i also would want the counters to be displayed in the same row number as their weeknumber so the first counter i mentioned would be displayed in row 39 and the other one would be displayed in row 23
Im sorry if what im asking here is confusing,if you have any question ask away and ill try my best to answer
Thank you for reading
I recently made the code below which reads the values inside certain columns and verifies if they are all on the same row and increments if the combination is the same as the one defined
But now i want to add another feature to it and im not sure how to go about doing it which is why i need help
Basically there is column G in my second sheet(same sheet that receives all the other values) that receives dates in the format "dd/mm/yyyy" and i would like it so that depending on the week number associated with said date the counter would be placed in a different row in sheet15.
for example lets say that there are only these 5 rows filed in the columns i defined and these are the values present in that sheet :
i would want there to be 2 counters,1 for the row with : 1, 2, 3, 3/2/0, 28/09/2023 and 1, 2, 3, 3/1/0, 29/09/2023 and another counter for 1, 2, 3, 3/1/0, 05/06/2023
the first counter would have the number 2 being displayed because 2 rows have the correct combination and they share the same weeknumber associated with their dates and the other counter would have 1 because there's only one row present with the correct combination of values that has the same weeknumber
i also would want the counters to be displayed in the same row number as their weeknumber so the first counter i mentioned would be displayed in row 39 and the other one would be displayed in row 23
Im sorry if what im asking here is confusing,if you have any question ask away and ill try my best to answer
Thank you for reading
Code:
Sub Button1_Click() 'Leaks
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim searchRange As Range
Dim countRange As Range
Dim count As Long
Dim searchValue1 As String
Dim searchValue2 As String
Dim searchValue3 As String
Dim searchValue4 As Variant ' Change the data type to Variant
' Define the search range in Sheet2 where you want to look for the data combination
Set searchRange = Sheet2.Range("B1:H" & Sheet2.Cells(Rows.count, "H").End(xlUp).row) ' Modify the range as per your data
' Define the range in Sheet15 where you want to store the count
Set countRange = Sheet15.Range("P1") ' Modify the cell as per your preference
' Clear previous count
countRange.value = ""
' Define the search values (combination of data)
searchValue1 = "1"
searchValue2 = "2"
searchValue3 = "3"
searchValue4 = Array("3/1/0", "3/2/0") ' Modify the values as per your requirement
' Convert the search range to a variant array for faster processing
Dim dataArr As Variant
dataArr = searchRange.value
' Loop through the array to search for the combination of values
Dim i As Long
Dim numRows As Long
Dim foundCount As Long
numRows = UBound(dataArr, 1)
For i = 1 To numRows
' Check if each search value is found in the row
If dataArr(i, 1) = searchValue1 And _
dataArr(i, 2) = searchValue2 And _
dataArr(i, 3) = searchValue3 And _
IsValueInArray(dataArr(i, 7), searchValue4) Then ' Use a helper function to check if value is in array
foundCount = foundCount + 1
End If
Next i
' Store the count in the count range of Sheet15
countRange.value = foundCount
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Private Function IsValueInArray(value As Variant, arr As Variant) As Boolean
' Helper function to check if value is in array
Dim i As Long
For i = LBound(arr) To UBound(arr)
If value = arr(i) Then
IsValueInArray = True
Exit Function
End If
Next i
IsValueInArray = False
End Function
Last edited: