Forum Discussion
le00p
Oct 26, 2023Copper Contributor
Seeking Assistance for Developing a VBA Tool in Excel
Dear Community, I am currently working on a project where I aim to develop a custom VBA tool in Excel to automate certain tasks. The primary objectives of my VBA tool are: Find the earliest pos...
NikolinoDE
Oct 27, 2023Platinum Contributor
Maybe it will help you further in your project.
I recommend creating a backup of your file before running the code.
Sub FindEarliestDate()
Dim ProjectDuration As Long
Dim AvailableDate As Date
Dim Employee As Range
Dim Machine As Range
Dim DateCell As Range
' Get project duration from cell D2
ProjectDuration = Range("D2").Value
' Loop through table to find earliest available date
For Each Employee In Range("A2:A100") ' Adjust the range as needed
If Employee.Value = "x" Then ' Check if employee is selected
For Each Machine In Range("C2:C100") ' Adjust the range as needed
If Machine.Value <> "" Then ' Check if machine is selected
For Each DateCell In Employee.Offset(0, 4).Resize(1, ProjectDuration).Cells ' Adjust the offset and resize as needed
If DateCell.Value = "" Then
' Found an available date
AvailableDate = DateCell.Value
Exit Sub
End If
Next DateCell
End If
Next Machine
End If
Next Employee
' Display the earliest available date in cell D1
Range("D1").Value = AvailableDate
End Sub