Forum Discussion
Rashaud35
Nov 05, 2022Copper Contributor
Trying to use VBA to clear cell contents but not the formula/format from specified cell
I am using the following code to clear the contents of a row, as part of a "clear button" I've created in my spreadsheet, but there's one Cell in each row that has a quotient formula in it. I would l...
- Nov 05, 2022
Range("A9:J9").SpecialCells(xlBlanks).EntireRow is the same as Range("A9").EntireRow and as Rows(9).
So there is no need to specify A9:J9 and SpecialCells(xlBlanks)
You might use
Rows(9).SpecialCells(xlCellTypeConstants).ClearContents
HansVogelaar
Nov 06, 2022MVP
You'll get that error of the specified row doesn't contain any fixed values. To avoid the error, insert the line
On Error Resume Next
at the beginning of the macro.
But ClearContents should only delete the cell contents, not their formatting. When you enter a value again, you should see the previously set formatting.
Rashaud35
Nov 06, 2022Copper Contributor
HansVogelaar Yep, you're right buddy! Thanks so much for your help with this! You're awesome!