After clicking OK, all other cell values have been deleted but just leaving the selected ranges, see screenshot: Then press F5 key to run this code, and a prompt box is popped out to remind you to select the range of cells that you want to keep, if you have selected the ranges in step1, please click OK, if not, you can select the cells you want in the prompt box, and enter the commas to separate the multiple ranges, then click OK button, see screenshot:ĥ. Set xRg = Application.InputBox("Please select the ranges want to keep", "Kutools for Excel", xAddress,, ,, , 8)Ĥ.
VBA code: delete all cell values but the selected ranges Sub ClearAllExceptSelection() In the Microsoft Visual Basic for Application window dialog box, click Insert > Module, then copy and paste the below VBA code into the Module window. Press Alt + F11 keys simultaneously to open the Microsoft Visual Basic for Application window.ģ. Please hold the Ctrl key to select the cells that you want to keep.Ģ.
There is no direct way for you to delete all of the unselected cell values at once, but, the following VBA code may help you, please do as follows:ġ. In Excel, we can quickly and directly delete the selected ranges, but have you ever tried to delete other cell contents except the selected ranges? This article, I will introduce some tricks for you to solve this task in Excel quickly and easily.ĭelete all but selected ranges with VBA codeĭelete all but selected ranges with Select Range Helper of Kutools for Excelĭelete all but selected ranges with Copy Ranges of Kutools for Excel
How to delete all but selected ranges in Excel?