View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Code to delete rows based on value

'GS[_2_ Wrote:
;1613973']one way, perhaps...

Sub Delete_SelectiveRows()
Dim vCriteria, vData, v, s1$, n&, j&
vCriteria = Split(Range("A1").Value, ",")
vData = Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
For n = UBound(vData) To LBound(vData) Step -1
For j = LBound(vCriteria) To UBound(vCriteria)
If InStr(1, vData(n, 1), vCriteria(j)) 0 Then
If Not InStr(1, s1, "0" & n + 1) 0 Then
s1 = s1 & "," & n + 1
End If
End If
Next 'j
Next 'n
For Each v In Split(Mid(s1, 2), ",")
Rows(v).Delete
Next 'v
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Garry,

I failed to mention in my post that I am almost completely unfamiliar
with VBA in Excel. That code I had was Frankenstein-ed together from
bits of code I came across. Therefore, I do not know how to insert my
parameters into your code. Thanks for your help.


I see!
Put your *roughly 40 values* in A1 as a comma delimited list like
this...

11327,11328,11329...

so your list in colA starts in A2. You can modify this layout to suit
your data layout so long as you edit the code to reflect where the
values are stored and where the list begins in colA. (You can store the
values anywhere but it should be in a row *above* where the list
starts.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion