Private Sub ComboBox1_Change()
If blnHaltChange Then Exit Sub
'Dim bfr As Long
'bfr = ComboBox1.Value
If blnHaltChange2 Then GoTo 40
If Application.WorksheetFunction.CountIf(Worksheets("Overview").Range("AJ:AJ"), ComboBox1.Value) = 0 Then MsgBox "No sub-tasks currently set up for this project": Exit Sub
blnHaltChange = True
40 If Application.WorksheetFunction.CountIf(Worksheets("Overview").Range("AJ:AJ"), ComboBox1.Value) = 0 Then GoTo 10
Range("A2").Value = Worksheets("Template").ComboBox1.Value
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim MatchVar
MatchVar = Application.Match(Val(ComboBox1.Value), Worksheets("Project").Range("A:A"), 0)
If Range("U1").Value <> "Stores" Then
Range("B6").Value = "Start date"
Else
Range("J6").Value = Worksheets("Project").Cells(MatchVar, "AX")
End If
Sheets("Template").Range("A78:L87").ClearContents
Set Sh = Worksheets("Adhoc")
LR = Sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = Sh.Range("A2:A" & LR)
With rng
Set Cell = .Find(What:=ComboBox1.Value, After:=.Cells(1, 1), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
If Not Cell Is Nothing Then
FirstAddr = Cell.Address
Do
With Sheets("Template").Range("A90").End(xlUp).Offset(1, 0)
.Value = Cell.EntireRow.Cells(1, 7).Value
.Offset(0, 1).Value = Cell.EntireRow.Cells(1, 9).Value
If Cell.EntireRow.Cells(1, 13).Value = "Y" Then .Offset(0, 2).Value = Cell.EntireRow.Cells(1, 11).Value: .Offset(0, 3).Value = Cell.EntireRow.Cells(1, 12).Value
End With
Set Cell = .FindNext(Cell)
Loop While Not Cell Is Nothing And Cell.Address <> FirstAddr
End If
End With
Set rng = Nothing
Set Cell = Nothing
Application.EnableEvents = True
Columns("AF:AG").ClearContents
Dim rngToCopy As Range
With Sheets("Overview")
.AutoFilterMode = False
.Range("Aj:AJ").AutoFilter field:=1, Criteria1:=Range("a2").Value
With .AutoFilter.Range
On Error Resume Next
Set rngToCopy = .Offset(1).Resize(.Rows.Count - 1).EntireRow.Resize(, 1)
On Error GoTo 0
If blnHaltChange2 Then GoTo 47
If rngToCopy Is Nothing Then MsgBox "No tasks for given project id!...": Exit Sub
47 If rngToCopy Is Nothing Then blnHaltChange3 = True: Exit Sub
End With
rngToCopy.Copy Destination:=Sheets("Template").Range("AF1")
Set rngToCopy = .AutoFilter.Range.Offset(1, 38)
rngToCopy.Copy Destination:=Sheets("Template").Range("AG1")
.AutoFilterMode = False
End With
blnHaltChange = False
Application.ScreenUpdating = True
Exit Sub
10
blnHaltChange3 = True
blnHaltChange = False
Application.ScreenUpdating = True
End Sub