Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 177
Default "next without for" macro error

I am trying to make hyperlinks from list of addresses. I am using this
macro and am getting a "next without for" error at the end. Can someone tell
me what I need to do to fix this? Thanks,

Todd


Sub MakeHyperlinkFormulas()
Dim cell As Range
Dim hyperlinkaddress As String, hyperlinktext As String
For Each cell In Selection
hyperlinkaddress = Trim(cell.Text)
hyperlinktext = Trim(cell.Text)
If hyperlinktext = "" Then GoTo skipit
If hyperlinktext < "" Then
If InStr(1, hyperlinkaddress, "@") Then
If LCase(Left(hyperlinkaddress, 7)) < "mailto:" Then
hyperlinkaddress = "mailto:" & hyperlinkaddress
End If
Else
If InStr(1, hyperlinkaddress, ".") = 0 Then GoTo skipit
If LCase(Left(hyperlinkaddress, 7)) < "http://" Then
hyperlinkaddress = "http://" & hyperlinkaddress
End If
End If
cell.Formula = "=HYPERLINK(""" & hyperlinkaddress & _
""",""" & hyperlinktext & """)"
skipit:
Next cell
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default "next without for" macro error

Hi Todd,

You don't need this line:
If hyperlinktext = "" Then GoTo skipit
because your code only procedes if your variable is not empty. Subsequently,
the label "skipit:" can go! Try the following..

Revised code:
Sub MakeHyperlinkFormulas()
Dim cell As Range
Dim hyperlinkaddress As String, hyperlinktext As String
For Each cell In Selection
hyperlinkaddress = Trim(cell.Text)
hyperlinktext = Trim(cell.Text)
If hyperlinktext < "" Then
If InStr(1, hyperlinkaddress, "@") Then
If LCase(Left(hyperlinkaddress, 7)) < "mailto:" Then
hyperlinkaddress = "mailto:" & hyperlinkaddress
End If
Else
If InStr(1, hyperlinkaddress, ".") 0 Then 'if it's there
If LCase(Left(hyperlinkaddress, 7)) < "http://" Then
hyperlinkaddress = "http://" & hyperlinkaddress
End If
End If
End If
cell.Formula = "=HYPERLINK(""" & hyperlinkaddress & _
""",""" & hyperlinktext & """)"
Next cell
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default "next without for" macro error

correction: my post is missing the last "End If". It's the same one yours is
missing <BTW, which is why you're getting the error; -your still in the "If"
block and trying to execute "Next" which has no "For" within the "If" block.

With the code below, if hyperlinktext = "" then it skips everything and
executes the "Next" statement.

Sub MakeHyperlinkFormulas()
Dim cell As Range
Dim hyperlinkaddress As String, hyperlinktext As String
|--For Each cell In Selection
| hyperlinkaddress = Trim(cell.Text)
| hyperlinktext = Trim(cell.Text)
| |--If hyperlinktext < "" Then
| | |--If InStr(1, hyperlinkaddress, "@") Then
| | | |--If LCase(Left(hyperlinkaddress, 7)) < "mailto:" Then
| | | | hyperlinkaddress = "mailto:" & hyperlinkaddress
| | | |--End If
| | |--Else
| | | |--If InStr(1, hyperlinkaddress, ".") 0 Then 'if it's there
| | | | |--If LCase(Left(hyperlinkaddress, 7)) < "http://" Then
| | | | | hyperlinkaddress = "http://" & hyperlinkaddress
| | | | |--End If
| | | |--End If
| | |--End If
| | cell.Formula = "=HYPERLINK(""" & hyperlinkaddress & _
| | """,""" & hyperlinktext & """)"
| |--End If
|--Next cell
End Sub

Sorry about that! ..better get some more coffee!
Regards,
GS
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 222
Default "next without for" macro error

Do your IF ... END IFs balance up because that can sometimes showup as the
kind of error you are experiencing

"Todd" wrote:

I am trying to make hyperlinks from list of addresses. I am using this
macro and am getting a "next without for" error at the end. Can someone tell
me what I need to do to fix this? Thanks,

Todd


Sub MakeHyperlinkFormulas()
Dim cell As Range
Dim hyperlinkaddress As String, hyperlinktext As String
For Each cell In Selection
hyperlinkaddress = Trim(cell.Text)
hyperlinktext = Trim(cell.Text)
If hyperlinktext = "" Then GoTo skipit
If hyperlinktext < "" Then
If InStr(1, hyperlinkaddress, "@") Then
If LCase(Left(hyperlinkaddress, 7)) < "mailto:" Then
hyperlinkaddress = "mailto:" & hyperlinkaddress
End If
Else
If InStr(1, hyperlinkaddress, ".") = 0 Then GoTo skipit
If LCase(Left(hyperlinkaddress, 7)) < "http://" Then
hyperlinkaddress = "http://" & hyperlinkaddress
End If
End If
cell.Formula = "=HYPERLINK(""" & hyperlinkaddress & _
""",""" & hyperlinktext & """)"
skipit:
Next cell
End Sub

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
Shortcut key for "Paste Options" and "Error Checking" buttons? johndog Excel Discussion (Misc queries) 1 October 6th 06 11:56 AM
What is Error "Method "Paste" of object "_Worksheet" failed? vat Excel Programming 7 February 17th 06 08:05 PM
"Subscript out of range" error for: Workbooks("Test1.xls").Save Just12341234 Excel Programming 2 June 17th 05 03:16 PM
"Clean Me" Macro is giving "#VALUE!" error in the Notes field. Ryan Watkins Excel Programming 1 June 11th 05 12:25 AM
Getting "compile error" "method or data member not found" on reinstall Bp Excel Programming 1 April 23rd 04 04:42 PM


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