So not sure if this is the correct way to go about this as I'm just beginning to learn to write in VBA.
I had created a code that would loop through my data and find basically if a status was in a specific state, which was "Received" if it wasn't, it would essentially be in another status, but I didn't care what that status was because I would automatically know that it was not received. So, I needed to simply know whether it's received or not received.
My data was originally formatted in such a way where it would be "Status" "Date" "Status" "Date" "Status" "Date"
, etc, all within one row. Each row would represent one ID
.
Now, my data set has changed to become:
- 1st row -
"ID" "Status" "Date"
- 2nd row -
"ID" "Status" "Date"
However, my problem now is that one ID
can go on and have multiple status, so it can go on for 7 rows with the same ID
, whereas another one can simply have 2 different status and therefore be represented by only 2 rows.
Now, I'm a little confused as how this would work with loops? Is there any way to go about representing each individual ID
and having the loop only loop through the amount of rows each ID
has associated to them?
Here is my original code:
Sub CheckDates()
Dim count As Integer
Dim i As Integer
Dim j As Integer
Sheets(1).Select
lastrow = ActiveSheet.Cells(Rows.count, "B").End(xlUp).Row
'have to keep data in a table for this to actually work as it ctrls+left to the table, which will end where the very last text of any row is
lastcolumn = ActiveSheet.Cells(3, Columns.count).End(xlToLeft).Column
count = 0
i = 4
j = lastcolumn
For i = 4 To lastrow
For j = lastcolumn To 6 Step (-1)
If Sheet1.Cells(i, j) < Sheet2.Cells(1, 1) And Sheet1.Cells(i, j - 1) = "Reçu" Then
count = count + 1
Cells(i, 1).Interior.ColorIndex = 6
GoTo NextIteration
End If
Next j
NextIteration:
Next i
Sheet2.Cells(1, 7) = count
Sheets(2).Select
'Runs the DeleteSAC Macro
Call DeleteSAC
End Sub
Sample data: