I am trying to learn how I can program into a macro the function of clearing, and not deleting, a cell in column k, n and o if it is equal to a cerain value. These values would be #N/A, 1/0/1900 and 0 respectively. Thank you for your help.
I am trying to learn how I can program into a macro the function of clearing, and not deleting, a cell in column k, n and o if it is equal to a cerain value. These values would be #N/A, 1/0/1900 and 0 respectively. Thank you for your help.
For N/A I would use the following
for the other two its basically the sameIf iserror(sheets("myworksheet").range("K1").value) Then sheets("Myworksheet").range("K1").clearcontents
Hope this helpsif (Sheets("myworksheet").range("N1").value = 0) Then sheets("Myworksheet").range("N1").clearcontents
Another approach that does more than one row at a time:
Option Explicit Sub Deletions() Dim Rng As Range, cell As Range 'Delete errors all at once in the entire column(s) Range("K:K,N:O").SpecialCells(xlCellTypeFormulas, 16).ClearContents 'Evaluate cells and delete blanks and zeros Set Rng = Range("K:K,N:O").SpecialCells(xlCellTypeFormulas) For Each cell In Rng If cell.Value = 0 Then cell.ClearContents Next cell Set Rng = Nothing End Sub
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks