Forum Discussion
How to clean content from a cell with dropdown list
If you are doing this with VBA, try ClearContents method instead of Clear like...
Range("A1:A10").ClearContents
- mbehringJul 08, 2020Copper Contributor
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 SubThanks.
Mario
- Subodh_Tiwari_sktneerJul 08, 2020Silver Contributor
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.
- mbehringJul 10, 2020Copper Contributor
It worked perfectly! Thank you very much. I really appreciate it.
Cheers!
Mario