Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,670
Default Macro auto insert/delete

Afternoon,
I am trying to use a macro that will delete any row that has a cell with the
value of "#VALUE!" in it.

I have tried several macro examples found on this and other websites, one
such one like this:
-----------
Sub DeleteRows()
Dim strToDelete As String
Dim rngSrc As Range
Dim NumRows As Integer
Dim ThisRow As Integer
Dim ThatRow As Integer
Dim ThisCol As Integer
Dim J As Integer
Dim DeletedRows As Integer

strToDelete = "#VALUE!"
Set rngSrc = ActiveSheet.Range(ActiveWindow.Selection.Address)

NumRows = rngSrc.Rows.Count
ThisRow = rngSrc.Row
ThatRow = ThisRow + NumRows - 1
ThisCol = rngSrc.Column

For J = ThatRow To ThisRow Step -1
If Cells(J, ThisCol) = strToDelete Then
Rows(J).Select
Selection.Delete Shift:=xlUp
DeletedRows = DeletedRows + 1
End If
Next J
MsgBox "Number of deleted rows: " & DeletedRows
End Sub
----------------
Except the line containing "strToDelete = "#VALUE!"" throws an error and the
program will not continue. It works fine if I use "strToDelete = "bob"".
I looked up an escape character, it seems to be " so I tried ""#VALUE"!"
and many other variants, no success.
Any suggestions on how to delete rows that contain #VALUE! ?


Thank you for taking your time to read and respond.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,670
Default Macro auto insert/delete

Sorry, Excel 2003.
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,670
Default Macro auto insert/delete

I would like to apologize, after I posted I figured out the answer:
Delete all rows with the specified cell that is not numeric!

Have a great day.
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro auto insert/delete

or...


If Cells(J, ThisCol).Text = strToDelete Then

Eric wrote:

Afternoon,
I am trying to use a macro that will delete any row that has a cell with the
value of "#VALUE!" in it.

I have tried several macro examples found on this and other websites, one
such one like this:
-----------
Sub DeleteRows()
Dim strToDelete As String
Dim rngSrc As Range
Dim NumRows As Integer
Dim ThisRow As Integer
Dim ThatRow As Integer
Dim ThisCol As Integer
Dim J As Integer
Dim DeletedRows As Integer

strToDelete = "#VALUE!"
Set rngSrc = ActiveSheet.Range(ActiveWindow.Selection.Address)

NumRows = rngSrc.Rows.Count
ThisRow = rngSrc.Row
ThatRow = ThisRow + NumRows - 1
ThisCol = rngSrc.Column

For J = ThatRow To ThisRow Step -1
If Cells(J, ThisCol) = strToDelete Then
Rows(J).Select
Selection.Delete Shift:=xlUp
DeletedRows = DeletedRows + 1
End If
Next J
MsgBox "Number of deleted rows: " & DeletedRows
End Sub
----------------
Except the line containing "strToDelete = "#VALUE!"" throws an error and the
program will not continue. It works fine if I use "strToDelete = "bob"".
I looked up an escape character, it seems to be " so I tried ""#VALUE"!"
and many other variants, no success.
Any suggestions on how to delete rows that contain #VALUE! ?

Thank you for taking your time to read and respond.


--

Dave Peterson
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
Auto insert macro CityGuy Excel Discussion (Misc queries) 4 February 5th 07 05:47 PM
Can I auto insert a worksheet when I insert a value in a cell. iainc Excel Worksheet Functions 0 April 27th 06 08:37 AM
how do I create a macro to auto insert rows? aashish Excel Worksheet Functions 1 January 30th 06 11:49 PM
how to insert row or delete while the auto filter is turn on? catherine Excel Discussion (Misc queries) 1 July 4th 05 01:39 PM
Is there a way to insert a formula, password or macro in an excel spreadsheet that will automatically delete the spreadsheet? oil_driller Excel Discussion (Misc queries) 1 February 8th 05 09:34 AM


All times are GMT +1. The time now is 09:05 PM.

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"