View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Vanna Vanna is offline
external usenet poster
 
Posts: 9
Default For each Next Loop

Thanks everyone for your responses. There are certainly many ways to do the
same thing. I've learn the short cut this time.

"Tom Ogilvy" wrote:

by the way. the reason you are getting the error is because

myrange = Range("E8:E500")

should be

Dim myRange as Range

set myRange = range("E8:E500")

You haven't yet gotten to the problems described by the others, so you need
to change your approach as well. This was just for information - not a
suggestion that that change will give the final result you desire.

--
Regards,
Tom Ogilvy

"Vanna" wrote:

Hi,
this is my first time trying out the ...for..each..next loop
I'm trying to delete the entire row if the cell in the E column contains the
word "USD". I tried the codes below and get "run time error 424, Object
require" error. Any help would be very much appreciated.

Sub deleteUSD()
Dim rng As Range

myrange = Range("E8:E500")

For Each rng In myrange
If rng.Value = "USD" Then
rng.EntireRow.Delete
End If
Next rng

End Sub