Can anyone correct my 3liner of codes?

edlim85

Board Regular
Joined
May 4, 2009
Messages
178
im getting a error here..pls help:eeek:

As the code, can tell what i want to do is go through each cells in my used range. clearcontent for cells containing "NA" or "#N/A"

For Each cell In w1.UsedRange.cells
If cell.Value = "NA" Or cell.Value = "#N/A" Then cell.ClearContents
Next cell


Regards
Edmund
 
<TABLE border=0 cellSpacing=0 cellPadding=6 width="100%"><TBODY><TR><TD style="BORDER-BOTTOM: 1px inset; BORDER-LEFT: 1px inset; BORDER-TOP: 1px inset; BORDER-RIGHT: 1px inset" class=alt2>If CStr(cell.Value) = "NA" Or CStr(cell.Value) = CStr(CVErr(xlErrNA)) Then cell.ClearContents </TD></TR></TBODY></TABLE>
Hmm...*strangely to me* all my repeated values are deleted as well..
i wonder if it is because of this line:eeek:

If CStr(cell.Value) = "NA" Or CStr(cell.Value) = CStr(CVErr(xlErrNA)) Then cell.ClearContents

hi Peter_SSs !,

my range varies. max 36rows and 27columns


Can you advise me code shld i go with?

Regards
Edmund
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi Peter_SSs,

I did. it works for "NA" but didnt clear "#N/A"

With w1.UsedRange
On Error Resume Next
.SpecialCells(xlCellTypeFormulas, xlErrors).ClearContents
On Error GoTo 0
.Replace What:="NA", Replacement:="", LookAt:=xlWhole, _
Searchformat:=False, ReplaceFormat:=False
End With

:)thanks
 
Upvote 0
My apology. I shld have make myself clear at the beginning. I doing a macro to rearrange data in a specific way. i have a line of coding in front that automatically return #N/A to cells if the row length(RowLenS) is more than the length of transposed range.

w1.cells(NR, 19).Resize(, RowLenS) = Application.Transpose(w1.Range(w1.cells(4, 8), w1.cells(LR, 8)).Value)

After rearranging all my data into required. I intend to clear content of cells containing "#N/A" and "NA". Where "NA" is one of the raw data.

hope this is clear. :)
 
Upvote 0
oh dear, the 1st few times i run it gives me Error 2042.

can i use this instead? it seem to work

With w1.UsedRange
On Error Resume Next
.SpecialCells(xlCellTypeFormulas, xlErrors).ClearContents
On Error GoTo 0
.Replace What:="NA", Replacement:="", LookAt:=xlWhole, _
Searchformat:=False, ReplaceFormat:=False
.Replace What:="#N/A", Replacement:="", LookAt:=xlWhole, _
Searchformat:=False, ReplaceFormat:=False
End With
 
Upvote 0
oh dear, the 1st few times i run it gives me Error 2042.
Rich (BB code):
With w1.UsedRange
On Error Resume Next
.SpecialCells(xlCellTypeFormulas, xlErrors).ClearContents
On Error GoTo 0
.Replace What:="NA", Replacement:="", LookAt:=xlWhole, _
Searchformat:=False, ReplaceFormat:=False
.Replace What:="#N/A", Replacement:="", LookAt:=xlWhole, _
Searchformat:=False, ReplaceFormat:=False
End With

can i use this instead? it seem to work
If it works, you can use it. :)

However, from what I can gather, you can probably leave out the red bit and it will still work. Try that.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,908
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top