JackReacher85
Banned user
- Joined
- Sep 14, 2021
- Messages
- 15
- Office Version
- 2016
- Platform
- Windows
All,
I have two lots of VBA that i need to have combined, my goal is to have a multi select drop down list applied only to cells in Column M ( first code) and add the date in to column O when all cells from Col A to M are completed (second code)
This is the multi select drop down code
This is the date addition code.
Ive racked my brain over this and cant seem to figure it out, any help is greatly appreciated.
I have two lots of VBA that i need to have combined, my goal is to have a multi select drop down list applied only to cells in Column M ( first code) and add the date in to column O when all cells from Col A to M are completed (second code)
This is the multi select drop down code
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
Dim selectedValue As String
Dim oldValue As String
' Check if the change is within column M
If Not Intersect(Target, Me.Range("M:M")) Is Nothing Then
Application.EnableEvents = False
For Each cell In Target
If Not IsEmpty(cell.Value) Then
' If the cell already contains data, append the new value
oldValue = cell.OldValue
selectedValue = cell.Value
If oldValue = "" Then
cell.Value = selectedValue
Else
' Avoid duplication
If InStr(1, oldValue, selectedValue, vbTextCompare) = 0 Then
cell.Value = oldValue & ", " & selectedValue
End If
End If
End If
Next cell
Application.EnableEvents = True
End If
End Sub
This is the date addition code.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rowNum As Long
Dim lastCol As Long
Dim cell As Range
Dim isComplete As Boolean
' Define the columns to check
lastCol = 13 ' Column M
' Check if the change affects columns A to M
If Not Intersect(Target, Me.Range("A:M")) Is Nothing Then
Application.EnableEvents = False
For Each cell In Target
rowNum = cell.Row
If rowNum > 1 Then ' Skip header row if any
isComplete = True
For i = 1 To lastCol
If IsEmpty(Me.Cells(rowNum, i)) Then
isComplete = False
Exit For
End If
Next i
' If complete, add date to column O
If isComplete Then
Me.Cells(rowNum, 15).Value = Date
Else
' Optionally clear date if not all cells are complete
Me.Cells(rowNum, 15).ClearContents
End If
End If
Next cell
Application.EnableEvents = True
End If
End Sub
Ive racked my brain over this and cant seem to figure it out, any help is greatly appreciated.