I neglected to indicate that the column where "a" is inputed isn't only on column "H" but H, O, V, AC, AJ, AQ, AX and BE so that when an "a" is inputed into these columns the cel.offset (, -3).value = Time and cel.Offset(, -2) = Date. Is there something I can copy and paste to make it work with all those columns?
You don't need a separate section per column. See my code below.
THe problem I'm having now is, if I highlight the column "H" where a's are inputed into to clear them all, it just freezes. Any thoughts
Yes, I have three thoughts:
1. Largely my fault.
When changing cells on the sheet in a Worksheet_Change event code you need to disable events. Otherwise when the code changes a cell (say by entering the date in a cell to the left) that is a change to the worksheet so the Worksheet_Change code is triggered again when it is not necessary. So every time an "a" is entered or a cell "Deleted" the code will be called 3 times instead of once.
2. If a large number of cells is to be processed, code will run much quicker if ScreenUpdating is turned off during the process. Again, I should have already had that in my code.
3. If you are using Excel 2007+ and you select the whole column and delete, the code has 1,048,576 cells to check/process. That will take a fair amount of time no matter what. Even with the improved code below and a reasonably new machine it takes about 40 seconds to process a whole column on my machine in Excel 2010. So it would be best to try not to use whole columns if you don't need to.
So try replacing the previous code with this:
<font face=Courier New><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br> <SPAN style="color:#00007F">Dim</SPAN> Changed <SPAN style="color:#00007F">As</SPAN> Range, Cel <SPAN style="color:#00007F">As</SPAN> Range<br> <br> <SPAN style="color:#00007F">Const</SPAN> myCols <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN> = "H:H, O:O, V:V, AC:AC, " _<br> & "AJ:AJ, AQ:AQ, AX:AX, BE:BE"<br> <br> <SPAN style="color:#00007F">Set</SPAN> Changed = Intersect(Target, Range(myCols))<br> <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Changed <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br> Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN><br> Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br> <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> Cel <SPAN style="color:#00007F">In</SPAN> Changed<br> <SPAN style="color:#00007F">Select</SPAN> <SPAN style="color:#00007F">Case</SPAN> Cel.Value<br> <SPAN style="color:#00007F">Case</SPAN> vbNullString<br> Cel.Offset(, -3).Resize(, 2).ClearContents<br> <SPAN style="color:#00007F">Case</SPAN> "a"<br> Cel.Offset(, -3).Value = Time<br> Cel.Offset(, -2).Value = <SPAN style="color:#00007F">Date</SPAN><br> <SPAN style="color:#00007F">Case</SPAN> <SPAN style="color:#00007F">Else</SPAN><br> <br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Select</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> Cel<br> Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN><br> Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br></FONT>