Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
JFH
 
Posts: n/a
Default Delete Row syntax conundrum

I have a button that Users can click to create new rows to specify
'Audiences' for a communication. When they click the button a new Audience
row with a cell with a drop down in appears each time. However when I want to
'Reset' the worksheet I only want there to be one Audience row remaining.

The code I currently have is as follows:

Sub IfStatement2()
Dim myList As Variant
Dim i As Long
myList = Array("Fred", "Sue", "Tim", "Tom")
For i = Range("A65536").End(xlUp).Row To 21 Step -1
If Not IsError(Application.Match(Range("A" & i).Value, myList)) Then
Range("A" & i).EntireRow.Delete
End If
Next i
End Sub

I have specified the items in the myList array accurately, but the 'match'
test seems to be a little loose in its application. Any text in the column
beneath my Audiences (even with no relation to the text specified in the
myList array) also seems to bring up a match and thus its row gets deleted.

Is there a way to force an 'exact match'?

Many thanks all.

  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

I think you just need an exact match

Sub IfStatement2()
Dim myList As Variant
Dim i As Long
myList = Array("Fred", "Sue", "Tim", "Tom")
For i = Cells(Rows.Count, "A").End(xlUp).Row To 21 Step -1
If Not IsError(Application.Match(Range("A" & i).Value, myList, 0))
Then
Rows(i).EntireRow.Delete
End If
Next i
End Sub


--
HTH

Bob Phillips

"JFH" wrote in message
...
I have a button that Users can click to create new rows to specify
'Audiences' for a communication. When they click the button a new Audience
row with a cell with a drop down in appears each time. However when I want

to
'Reset' the worksheet I only want there to be one Audience row remaining.

The code I currently have is as follows:

Sub IfStatement2()
Dim myList As Variant
Dim i As Long
myList = Array("Fred", "Sue", "Tim", "Tom")
For i = Range("A65536").End(xlUp).Row To 21 Step -1
If Not IsError(Application.Match(Range("A" & i).Value, myList)) Then
Range("A" & i).EntireRow.Delete
End If
Next i
End Sub

I have specified the items in the myList array accurately, but the 'match'
test seems to be a little loose in its application. Any text in the column
beneath my Audiences (even with no relation to the text specified in the
myList array) also seems to bring up a match and thus its row gets

deleted.

Is there a way to force an 'exact match'?

Many thanks all.



  #3   Report Post  
JFH
 
Posts: n/a
Default

Thanks a lot Bob - this works a treat!
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
Delete Row syntax conundrum username Excel Discussion (Misc queries) 5 May 24th 05 05:36 PM
How to delete blank rows John Mansfield Excel Discussion (Misc queries) 3 April 27th 05 11:48 PM
Cannot delete a macro Jeff B Excel Discussion (Misc queries) 3 February 15th 05 12:43 AM
How to delete macros Jaime Stuardo Excel Discussion (Misc queries) 2 February 14th 05 02:29 PM
delete row contains specific word in an macro Jean-Francois Excel Discussion (Misc queries) 4 January 11th 05 11:40 PM


All times are GMT +1. The time now is 09:36 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"