Excel 2010 code that clears content of a cell on open

Closed
jamhome Posts 1 Registration date Saturday August 30, 2014 Status Member Last seen August 31, 2014 - Aug 31, 2014 at 09:10 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Sep 9, 2014 at 11:34 AM
Hi

I am looking for code that clears content of a cell based on a value when the workbook opens.
I have several sheets in the workbook with varied cell locations where there is an x. Anywhere the x appears I want the code to clear contents.

I have searched the forum but I am not quite finding exactly what I need and limited in writing code to meet my needs. I hope my request is clear.
Related:

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Sep 9, 2014 at 11:34 AM
Hi Jamhome,

Try the following code:
Private Sub Workbook_Open()
Dim ws As Worksheet

For Each ws In Worksheets
    Do
        ws.Select
        Cells.Find(What:="x", lookat:=xlWhole).ClearContents
    Loop Until Cells.Find(What:="x", lookat:=xlWhole) Is Nothing
Next ws

End Sub


To implement, hit Alt+F11, locate "ThisWorkbook" on the left side of the newly opened window. Double click on it and paste the code in the big white field.

Best regards,
Trowa
0