Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 85
Default why doesn't this simple macro work in excel 2007?

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

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default why doesn't this simple macro work in excel 2007?

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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 85
Default why doesn't this simple macro work in excel 2007?

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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default why doesn't this simple macro work in excel 2007?

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

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default why doesn't this simple macro work in excel 2007?

hi
the msgbox was for test perposes only. should have mentioned that.

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



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default why doesn't this simple macro work in excel 2007?

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

  #7   Report Post  
Posted to microsoft.public.excel.misc
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
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 947
Default why doesn't this simple macro work in excel 2007?

If Isblank.Cells(i, 2) Then

Range(i, 2).Select.Delete


Hi. Since you don't want any blanks, I might get rid of those first.
Then, the rest of the code can skip this check.
This may not be correct, but may give you some ideas..

Sub Demo()
Dim Cell
Const K As String = "*@*"

'// Get rid of blanks first:
On Error Resume Next
[B:B].SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveSheet.UsedRange

'// Now, just test the remaining data
For Each Cell In [B:B].SpecialCells(xlCellTypeConstants).Cells
If Not (Cell Like K) Then Cell.Clear
Next Cell

[B:B].SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveSheet.UsedRange
End Sub


I don't know the answer to this one. Anyone?

If a cell has some text like abc@xyz
Then Excel sees this as a Hyperlink.
(The idea being we can assume this is ok for the op)

When looking at a cell's properties, I don't see any easy test for the cell being a Hyperlink.
Does anyone?

The closest I can find is based on this "Hyperlinks Object" help topic in Excel 2007.

For Each h in Worksheets(1).Hyperlinks

--
Dana DeLouis


"Dave Peterson" wrote in message ...

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
  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default why doesn't this simple macro work in excel 2007?

If you want to test to see if a cell contains an Insert|hyperlink type
hyperlink, you could use:

if somecell.Hyperlinks.Count 0 then



Dana DeLouis wrote:

If Isblank.Cells(i, 2) Then
Range(i, 2).Select.Delete


Hi. Since you don't want any blanks, I might get rid of those first.
Then, the rest of the code can skip this check.
This may not be correct, but may give you some ideas..

Sub Demo()
Dim Cell
Const K As String = "*@*"

'// Get rid of blanks first:
On Error Resume Next
[B:B].SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveSheet.UsedRange

'// Now, just test the remaining data
For Each Cell In [B:B].SpecialCells(xlCellTypeConstants).Cells
If Not (Cell Like K) Then Cell.Clear
Next Cell

[B:B].SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveSheet.UsedRange
End Sub

I don't know the answer to this one. Anyone?

If a cell has some text like abc@xyz
Then Excel sees this as a Hyperlink.
(The idea being we can assume this is ok for the op)

When looking at a cell's properties, I don't see any easy test for the cell being a Hyperlink.
Does anyone?

The closest I can find is based on this "Hyperlinks Object" help topic in Excel 2007.

For Each h in Worksheets(1).Hyperlinks

--
Dana DeLouis

"Dave Peterson" wrote in message ...
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


--

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
macro does not work in Office 2007... suggestions: jatman Excel Discussion (Misc queries) 2 June 13th 08 12:11 AM
Simple links in Excel 2007 MM[_2_] Excel Worksheet Functions 4 October 24th 07 06:48 PM
Excel 2003 - Simple IF() Formula Will Not Work For Me scott Excel Worksheet Functions 9 November 7th 06 06:13 PM
Why won't this simple VBA script work in excel 2002? Calle Excel Discussion (Misc queries) 1 May 29th 06 12:21 PM
Problem with Excel: Simple multiplying calculations don't work. dforty3 Excel Discussion (Misc queries) 3 July 22nd 05 05:47 PM


All times are GMT +1. The time now is 08:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"