How to clean content from a cell with dropdown list

%3CLINGO-SUB%20id%3D%22lingo-sub-1508198%22%20slang%3D%22en-US%22%3EHow%20to%20clean%20content%20from%20a%20cell%20with%20dropdown%20list%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1508198%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20all%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20created%20a%20dropdown%20list%20for%20a%20group%20of%20cells%20in%20a%20column%20and%20I%20am%20using%20a%20VBA%20code%20so%20the%20user%20can%20select%20more%20than%20one%20item%20from%20the%20list.%20It's%20working%20fine.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20problem%20is%20that%20once%20an%20item%20or%20items%20are%20selected%2C%20it's%20not%20possible%20to%20clear%20the%20selection%20or%20change%20or%20deselect%20any%20item...%20and%20it's%20not%20possible%20to%20clear%20the%20cell%20content%20either.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20only%20way%20I've%20found%20to%20clear%20the%20cell%20content%20is%20actually%20using%20the%20%22CLEAR%20ALL%22%20button%20on%20the%20DATA%20Validation%20dialog%20window%2C%20which%20is%20not%20what%20I%20want.%20I%20just%20want%20to%20be%20able%20to%20clear%20the%20content%20so%20that%20the%20user%20can%20select%20items%20again%20if%20he%2Fshe%20wants.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20help%20is%20appreciated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1508198%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20on%20Mac%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1508227%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20clean%20content%20from%20a%20cell%20with%20dropdown%20list%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1508227%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F722022%22%20target%3D%22_blank%22%3E%40mbehring%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20are%20doing%20this%20with%20VBA%2C%20try%20ClearContents%20method%20instead%20of%20Clear%20like...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERange(%22A1%3AA10%22).ClearContents%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1508591%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20clean%20content%20from%20a%20cell%20with%20dropdown%20list%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1508591%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20quick%20answer.%20However%2C%20where%20should%20I%20put%20this%20code%20line%20you've%20sent%3F%20I%20am%20not%20proficient%20in%20VBA.%20This%20is%20the%20code%20I%20am%20using%20to%20be%20able%20to%20select%20more%20than%201%20item%20from%20the%20dropdown%20list%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%3CBR%20%2F%3E'UpdatebyExtendoffice20180510%3CBR%20%2F%3EDim%20xRgVal%20As%20Range%3CBR%20%2F%3EDim%20xStrNew%20As%20String%3CBR%20%2F%3EOn%20Error%20Resume%20Next%3CBR%20%2F%3ESet%20xRgVal%20%3D%20Cells.SpecialCells(xlCellTypeAllValidation)%3CBR%20%2F%3EIf%20(Target.Count%20%26gt%3B%201)%20Or%20(xRgVal%20Is%20Nothing)%20Then%20Exit%20Sub%3CBR%20%2F%3EIf%20Intersect(Target%2C%20xRgVal)%20Is%20Nothing%20Then%20Exit%20Sub%3CBR%20%2F%3EApplication.EnableEvents%20%3D%20False%3CBR%20%2F%3ExStrNew%20%3D%20Target.Value%3CBR%20%2F%3EApplication.Undo%3CBR%20%2F%3ExStrNew%20%3D%20xStrNew%20%26amp%3B%20%22%20%22%20%26amp%3B%20Target.Value%3CBR%20%2F%3ETarget.Value%20%3D%20xStrNew%3CBR%20%2F%3EApplication.EnableEvents%20%3D%20True%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3CP%3EMario%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1508612%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20clean%20content%20from%20a%20cell%20with%20dropdown%20list%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1508612%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F722022%22%20target%3D%22_blank%22%3E%40mbehring%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20replace%20your%20code%20with%20the%20following%20code%20and%20you%20would%20be%20able%20to%20delete%20the%20cell%20content%20using%20the%20Delete%20key%20from%20the%20keyboard.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%0ADim%20xRgVal%20As%20Range%0ADim%20xStrNew%20As%20String%0AOn%20Error%20Resume%20Next%0ASet%20xRgVal%20%3D%20Cells.SpecialCells(xlCellTypeAllValidation)%0AIf%20(Target.Count%20%26gt%3B%201)%20Or%20(xRgVal%20Is%20Nothing)%20Then%20Exit%20Sub%0AIf%20Intersect(Target%2C%20xRgVal)%20Is%20Nothing%20Then%20Exit%20Sub%0AIf%20Target%20%26lt%3B%26gt%3B%20%22%22%20Then%0A%20%20%20%20Application.EnableEvents%20%3D%20False%0A%20%20%20%20xStrNew%20%3D%20Target.Value%0A%20%20%20%20Application.Undo%0A%20%20%20%20xStrNew%20%3D%20xStrNew%20%26amp%3B%20%22%20%22%20%26amp%3B%20Target.Value%0A%20%20%20%20Target.Value%20%3D%20xStrNew%0A%20%20%20%20Application.EnableEvents%20%3D%20True%0AEnd%20If%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3ELet%20me%20know%20if%20you%20need%20a%20separate%20code%20to%20clear%20the%20cell%20content%20from%20the%20dropdown%20cells%20at%20once.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1514694%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20clean%20content%20from%20a%20cell%20with%20dropdown%20list%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1514694%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20worked%20perfectly!%20Thank%20you%20very%20much.%20I%20really%20appreciate%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers!%3C%2FP%3E%3CP%3EMario%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1514926%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20clean%20content%20from%20a%20cell%20with%20dropdown%20list%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1514926%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F722022%22%20target%3D%22_blank%22%3E%40mbehring%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou're%20welcome%20Mario!%20Glad%20it%20worked%20as%20desired.%3C%2FP%3E%3CP%3EPlease%20take%20a%20minute%20to%20accept%20the%20post%20with%20the%20proposed%20answer%20as%20a%20Best%20Response%20in%20order%20to%20mark%20your%20question%20as%20Solved.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%3C%2FP%3E%3CP%3ESubodh%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hello all,

 

I've created a dropdown list for a group of cells in a column and I am using a VBA code so the user can select more than one item from the list. It's working fine.

 

The problem is that once an item or items are selected, it's not possible to clear the selection or change or deselect any item... and it's not possible to clear the cell content either.

 

The only way I've found to clear the cell content is actually using the "CLEAR ALL" button on the DATA Validation dialog window, which is not what I want. I just want to be able to clear the content so that the user can select items again if he/she wants.

 

Any help is appreciated.

 

Thanks.

5 Replies

@mbehring 

If you are doing this with VBA, try ClearContents method instead of Clear like...

 

Range("A1:A10").ClearContents

@Subodh_Tiwari_sktneer 

 

Thank you for your quick answer. However, where should I put this code line you've sent? I am not proficient in VBA. This is the code I am using to be able to select more than 1 item from the dropdown list:

 

Private Sub Worksheet_Change(ByVal Target As Range)
'UpdatebyExtendoffice20180510
Dim xRgVal As Range
Dim xStrNew As String
On Error Resume Next
Set xRgVal = Cells.SpecialCells(xlCellTypeAllValidation)
If (Target.Count > 1) Or (xRgVal Is Nothing) Then Exit Sub
If Intersect(Target, xRgVal) Is Nothing Then Exit Sub
Application.EnableEvents = False
xStrNew = Target.Value
Application.Undo
xStrNew = xStrNew & " " & Target.Value
Target.Value = xStrNew
Application.EnableEvents = True
End Sub

 

Thanks.

Mario

@mbehring 

Please replace your code with the following code and you would be able to delete the cell content using the Delete key from the keyboard.

 

Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRgVal As Range
Dim xStrNew As String
On Error Resume Next
Set xRgVal = Cells.SpecialCells(xlCellTypeAllValidation)
If (Target.Count > 1) Or (xRgVal Is Nothing) Then Exit Sub
If Intersect(Target, xRgVal) Is Nothing Then Exit Sub
If Target <> "" Then
    Application.EnableEvents = False
    xStrNew = Target.Value
    Application.Undo
    xStrNew = xStrNew & " " & Target.Value
    Target.Value = xStrNew
    Application.EnableEvents = True
End If
End Sub

Let me know if you need a separate code to clear the cell content from the dropdown cells at once.

@Subodh_Tiwari_sktneer 

 

It worked perfectly! Thank you very much. I really appreciate it.

 

Cheers!

Mario

 

 

@mbehring 

You're welcome Mario! Glad it worked as desired.

Please take a minute to accept the post with the proposed answer as a Best Response in order to mark your question as Solved.

 

Regards,

Subodh