#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 58
Default Macro - Remove #n/a

I have a macro that places #n/a's in rows, the next step for it to do is
delete them. I would like it to delete out the WHOLE rows that get populated
#n/a, not columns.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Macro - Remove #n/a

I believe this code will work for you. Don't be confused by the fact that I
have a column defined to do some testing on - that's necessary. In the end,
entire rows with #N/A in that column (you may redefine it as needed in your
workbook) will be absolutely deleted - not just cleared out, but physically
deleted.

Since this is a destructive action, I suggest you first make a backup copy
of your workbook and put the code into either the backup or original and try
it to make sure it's doing what you want. That way, if something goes wrong
you'll still have an original copy of the workbook to fall back to.

To put this code into your workbook; open the workbook, press [Alt]+[F11] to
open the VB Editor, choose Insert | Module from the VBE menu and then copy
and paste the code into that module. Edit the column letter assigned to
constant testColumn as needed for your workbook. To use it, select the sheet
to be cleaned up, then use Tools | Macro | Macros and choose this one from
the list and click [Run].

Sub DeleteNARows()
'pick a column to test in, this
'column should be one that will have
'#N/A error displayed in it and that
'goes as far down the sheet as you need
'to examine for the #N/A conditions
'although not all entries have to be #N/A
'just something in them to the end
' Using column E for this example
' as E was where I put a VLOOKUP() formula
' to test/generate #N/A errors.
Const testColumn = "E" ' change as required
'no other changes to make
Dim naRowList As String
Dim anyRange As Range
Dim anyCellEntry As Range

'find area to examine:
Set anyRange = ActiveSheet.Range(testColumn & "1:" & _
ActiveSheet.Range(testColumn & _
Rows.Count).End(xlUp).Address)
'make list of rows that are to be deleted
For Each anyCellEntry In anyRange
If anyCellEntry.Text = "#N/A" Then
naRowList = naRowList & anyCellEntry.Row & _
":" & anyCellEntry.Row & ","
End If
Next
'remove the extra comma at the end of the list of rows
'that are to be deleted (if list is empty, exit sub)
If naRowList < "" Then
naRowList = Left(naRowList, Len(naRowList) - 1)
Else
'no #N/A entries found
Set anyRange = Nothing
Exit Sub
End If
Set anyRange = ActiveSheet.Range(naRowList)
anyRange.Delete Shift:=xlUp
Set anyRange = Nothing
End Sub


"Schwimms" wrote:

I have a macro that places #n/a's in rows, the next step for it to do is
delete them. I would like it to delete out the WHOLE rows that get populated
#n/a, not columns.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro - Remove #n/a

Are you placing these #n/a's in a single column?

Maybe you can just select that column
Edit|goto|special
constants and errors (nothing else checked)
edit|delete|entire row
(xl2003 menus)

Schwimms wrote:

I have a macro that places #n/a's in rows, the next step for it to do is
delete them. I would like it to delete out the WHOLE rows that get populated
#n/a, not columns.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 58
Default Macro - Remove #n/a

Awesome,

Thanks guys, both work like a charm.


"Schwimms" wrote:

I have a macro that places #n/a's in rows, the next step for it to do is
delete them. I would like it to delete out the WHOLE rows that get populated
#n/a, not columns.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro 4.remove D. Excel Discussion (Misc queries) 2 September 29th 07 02:52 PM
Macro to Remove Macro Text Rob Excel Discussion (Misc queries) 1 June 21st 07 11:49 PM
Remove Macro Moduel older pro[_2_] Excel Discussion (Misc queries) 4 February 23rd 07 03:12 PM
how do i remove password from xls vba macro? mahesh New Users to Excel 1 October 26th 06 10:22 AM
remove macro Ron New Users to Excel 2 June 1st 06 02:57 PM


All times are GMT +1. The time now is 05:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"