uss.Select
This line selects unprotected cells of the previously selected range ( In Selection - in the selected range). But you need to delete the data:
uss.ClearContents
If there are no unprotected cells in the selected range, your code will fall out into error. It is necessary to check the filling range:
If Not uss Is Nothing Then uss.ClearContents
The macro works with the selected range. If you need to clear all unprotected cells in the sheet, you can work with the UsedRange - custom range.
The code can be abbreviated if at least one cell is known in advance that needs to be cleared. Such a cell can be any empty or one, the deletion of data in which does not harm further work. Naturally, it must be unprotected.
Sub Clear_Cell() Dim r As Range, ur As Range Set ur = Cells(1, 1) ' ΠΎΡΠΈΡΠ°Π΅ΠΌΡΡ ΡΡΠ΅ΠΉΠΊΡ - Π² ΡΠΎΡΠΌΠΈΡΡΠ΅ΠΌΡΠΉ Π΄ΠΈΠ°ΠΏΠ°Π·ΠΎΠ½ ' For Each r In ActiveSheet.UsedRange ' ΠΏΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ ΡΡΠ΅ΠΉΠΊΠΈ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»ΡΡΠΊΠΎΠ³ΠΎ Π΄ΠΈΠ°ΠΏΠ°Π·ΠΎΠ½Π° ' If Not r.Locked Then Set ur = Union(ur, r) ' Π½Π΅Π·Π°ΡΠΈΡΠ΅Π½Π½ΡΠ΅ - Π² ΡΠΎΡΠΌΠΈΡΡΠ΅ΠΌΠΌΡΠΉ Π΄ΠΈΠ°ΠΏΠ°Π·ΠΎΠ½ ' Next r ur.ClearContents ' ΠΎΡΠΈΡΠ°ΠΌ ΡΡΠΎΡΠΌΠΈΡΠΎΠ²Π°Π½Π½ΡΠΉ Π΄ΠΈΠ°ΠΏΠ°Π·ΠΎΠ½ ' Set ur = Nothing ' ΠΎΡΠ²ΠΎΠ±ΠΎΠΆΠ΄Π°Π΅ΠΌ ΠΏΠ°ΠΌΡΡΡ ' End Sub
Along the way: do not call procedures, variables, and so on. reserved words. It is better to call the macro differently, for example: Sub Clear_Cell () .
If an object was assigned to a variable, it is desirable to clear the variable at the end of the work ( Set ur = Nothing )