View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default why doesn't this simple macro work in excel 2007?

I don't think you meant this syntax.

And you could use instr instead of worksheetfunction.find to stay with native
VBA.

FSt1 wrote:

hi
forget the left thing.
instead..
If Cells(i, 1) = WorksheetFunction.Find("@", Cells(i, 1), 2) < 1 Then
MsgBox "don't delete row"
End If
works better.

regards
FSt1

"FSt1" wrote:

hi
as to the second command. i noticed that and forgot to say somthing. sorry.
you don't need to select and delete . just delete.
Range(i, w).Delete
selecting sometimes slows things down. and vb knows were and what to do by
reference so selecting is most often not needed.
as to the @ find, try something like this....
If Left(Cells(i,2), 1) = "@" Then
MsgBox "it's ok"
End If

regards
FSt1

"ManhattanRebel" wrote:

Thank you, FSt1. That helped. I'm still having a problem. The second
command of Range(i, w). Select.Delete did not work. I substituted this
command: ActiveCell.EntireRow.Delete. That doesn't work, either. Are the
commands wrong, or is the previous line of code not instructing properly? I
am trying to determine if a cell has an email address in it. That is why I
ask if the value<"@", but I may need more in it. Any help appreciated.

-----------------------------------------------------------------------------
"FSt1" wrote:

hi
you left out a end if. vb will do that to you ie give the wrong error in
this situation. i don't know why but it will do the same in a do loop ie
leaving out an end if and tell you 'loop without a do'.

regards
FSt1

"ManhattanRebel" wrote:

I wrote this simple macro to just go through column B and delete rows that
don't have an email in them. It won't even compile. It tells me error
"Next without for".



Sub FindEmail()
'try to separate email addresses and add a comma at the end of them
FinalRow = Cells(65536, 2).End(xlUp).Row

For i = 1 To FinalRow
Cells(i, 2).Select
If Isblank.Cells(i, 2) Then
Range(i, 2).Select.Delete
Else
If Cells(i, 2).Value < "@" Then
Range(i, 2).Select.Delete
End If
Next i
End Sub


--

Dave Peterson