I'm trying to clear all cells on a sheet that are not in the Range between A1:F1
This is what my code looks like:
The idea was to go through each cell in WorkRange (which is every cell defined by the .UsedRange method -- which I'm assuming just means every non-empty cell in the sheet).![]()
Sub ClearTable() Sheets("Tables").Activate Dim WorkRange As Range Dim thisCell As Range Set WorkRange = ActiveSheet.UsedRange For Each Cell In WorkRange If Cell = Range("A1") Or Range("B1") Or Range("C1") Or Range("D1") Or Range("E1") Or Range("F1") Then Else Cell.Clear End If Next Cell End Sub
If the cell is in the range I don't want deleted then nothing happens, else clear the cell.
On the line "If Cell = Range("A1") Or Range("B1")...." It yields a Type Mismatch error.
Thoughts?
Thanks!











LinkBack URL
About LinkBacks
Register To Reply

Bookmarks