mysticmario
Active Member
- Joined
- Nov 10, 2021
- Messages
- 323
- Office Version
- 365
- Platform
- Windows
Hello again good people of MrExcel thsi is the loop:
I want else statement of this code to apply to an empty cell in collumn but only if cell in B and C column of this row is also empty, not the first empty cell it encounters in this column.
so the loops has to find the first empty cell in a row where B and C are also empty for this else statement.
Visual reference:
I have this set of data created by the else statement of my given code:
I run the loop using the same JobType.values but with a newer date,
and I get an update to jobtype with new set of hours but for the next day:
Now the next day my employee did none of these jobtypes, he in fact did new jobtype "M",
So when i try to use this loop as it is I get:
as you can see it replaced the first jobtype with new jobtype cause it doesn't know that it should use different empty cell.
I want to get this instead:
I cant wrap my head around how to this loops to act this way I tried using nested loop to find new empty cell ina row where B and C is also empty but it only broke the code completely.
Maybe someone has an idea how make it happen?
Thank you in advance!
VBA Code:
For Each emptyCell In dRng
If emptyCell.Value2 = CLng(FindDate) Then
Dim colNum As Integer
colNum = emptyCell.Column 'get the column number where the date was found
For b = emptyCell.Row + 1 To emptyCell.Row + 32 'start the loop from the next row of the found date cell
If Cells(b, colNum).Value = "" Then 'check if the cell is empty in the same column where the date was found
Set emptyCell = Cells(b, colNum)
' Add jobtype and hours
If Cells(emptyCell.Row, "B").Value = Me.employee.Value And Cells(emptyCell.Row, "C").Value = Me.JobType.Value Then
emptyCell.Value = Me.HoursCount.Value
emptyCellFound = True 'set the flag to indicate that an empty cell has been found
Exit For
Else
emptyCell.Value = Me.HoursCount.Value
Cells(emptyCell.Row, "C").Value = Me.JobType.Value
Cells(emptyCell.Row, "B").Value = Me.employee.Value
emptyCellFound = True 'set the flag to indicate that an empty cell has been found
Exit For 'exit the inner loop if an empty cell is found
End If
End If
Next b
End If
I want else statement of this code to apply to an empty cell in collumn but only if cell in B and C column of this row is also empty, not the first empty cell it encounters in this column.
so the loops has to find the first empty cell in a row where B and C are also empty for this else statement.
Visual reference:
I have this set of data created by the else statement of my given code:
I run the loop using the same JobType.values but with a newer date,
and I get an update to jobtype with new set of hours but for the next day:
Now the next day my employee did none of these jobtypes, he in fact did new jobtype "M",
So when i try to use this loop as it is I get:
as you can see it replaced the first jobtype with new jobtype cause it doesn't know that it should use different empty cell.
I want to get this instead:
I cant wrap my head around how to this loops to act this way I tried using nested loop to find new empty cell ina row where B and C is also empty but it only broke the code completely.
Maybe someone has an idea how make it happen?
Thank you in advance!