Forum Discussion
Trying to use VBA to clear cell contents but not the formula/format from specified cell
- 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
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 Hey Hans, thank you so much for your help with this and sorry about the late response. I think this worked, however, I still get a runtime error. I changed all the "range" to "row" and it cleared the cells and kept the formula in place, but the formatting still gets cleared out (font type, currency, etc.). I've attached a screenshot of the the error.
- HansVogelaarNov 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.
- Rashaud35Nov 06, 2022Copper Contributor
HansVogelaar Yep, you're right buddy! Thanks so much for your help with this! You're awesome!