Sub ManageCategoryEntries()
Dim AllEntriesRange As Range
Dim CurrentCategoryRange As Range
Dim UserName As String
Dim Cell As Range
Dim UserNameFoundInCurrent As Boolean
Dim UserNameFoundInAll As Boolean
' Define ranges and UserName
Set AllEntriesRange = Range("C7:L11")
Set CurrentCategoryRange = Range("C7:C11")
UserName = Application.UserName
' Check if there are any empty cells in the CurrentCategoryRange
If WorksheetFunction.CountBlank(CurrentCategoryRange) = 0 Then
MsgBox "Entries to this category are closed"
Exit Sub
End If
' Check if UserName is already in CurrentCategoryRange
UserNameFoundInCurrent = False
For Each Cell In CurrentCategoryRange
If Cell.Value = UserName Then
UserNameFoundInCurrent = True
Exit For
End If
Next Cell
If UserNameFoundInCurrent Then
MsgBox "Already listed"
Exit Sub
End If
' Search for UserName in AllEntriesRange and remove it if found
UserNameFoundInAll = False
For Each Cell In AllEntriesRange
If Cell.Value = UserName Then
Cell.Value = ""
UserNameFoundInAll = True
Exit For
End If
Next Cell
' Add UserName to the first empty cell in CurrentCategoryRange
If Not UserNameFoundInCurrent Then
For Each Cell In CurrentCategoryRange
If Cell.Value = "" Then
Cell.Value = UserName
Exit For
End If
Next Cell
End If
' If UserName was found and removed from AllEntriesRange, notify the user
If UserNameFoundInAll Then
MsgBox "Your entry moved to the category"
End If
End Sub
COMMENTS