Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Macro That doesn't work - Please help

I have a macro which converts urls in a column to the words "Tax Record" but
the macro will not work. When I run the Macro it prompts for Column and then
prompts for sheet name as expected. When valid inputis given to both
questions the Macro ends without error but does not convert the urls in the
column identified into the words "Tax Record"

I would appreicate any help I can get. The Marco is:

Sub chngelink()
'
' chngelink Macro
'
' Keyboard Shortcut: Ctrl+z
Dim MyCol As String
Dim MySht As String
On Error Resume Next
MyCol = InputBox("Enter column LETTER(S)")
MySht = InputBox("Enter sheet name")
Lastrow = Sheets(MySht).Cells(Cells.Rows.Count, MyCol).End(xlUp).Row
For Each c In Sheets(MySht).Range(MyCol & "2:" & MyCol & Lastrow)
c.Hyperlinks(1).TextToDisplay = "Tax record"
Next
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Macro That doesn't work - Please help

Jay Latimer,

I've included some code below for you to evaluate. I would consider
redesigning the InputBox for your column because you currently have no way of
testing that the user input is valid. Once you add the validation for the
first InputBox (i.e. strCol), you can get rid of the On Error statement. I
added a worksheet validation via setting the worksheet to a worksheet object.
Lastly, I used the Hyperlinks object (which works for inserted hyperlinks
and NOT for the HYPERLINK function) to loop through the hyperlink with the
range. I hope this helps.

Best,

Matthew Herbert

Sub ChangeLink()
Dim strCol As String
Dim strSht As String
Dim Wks As Worksheet
Dim Rng As Range
Dim lngLastRow As Long
Dim HLinks As Hyperlinks
Dim HLink As Hyperlink

On Error Resume Next
'maybe consider using Application.InputBox with a Type:=8, which
' will return a cell reference as a Range object
' (see Application.InputBox in VBE Help). This will
' make some of the validation easier, such as are there too
' many columns, did the user enter a number, etc.
strCol = InputBox("Enter column LETTER(S)")

strSht = InputBox("Enter sheet name")

'test if you have a valid worksheet
Set Wks = Worksheets(strSht)
If Wks Is Nothing Then Exit Sub

With Wks
lngLastRow = .Cells(.Rows.Count, strCol).End(xlUp).Row
Set Rng = Range(.Cells(2, strCol), .Cells(lngLastRow, strCol))
End With

'get a collection of hyperlinks within Rng
Set HLinks = Rng.Hyperlinks

'if a hyperlinks collection is returned, loop through each
' hyperlink and change the TextToDisplay property
If Not HLinks Is Nothing Then
For Each HLink In HLinks
HLink.TextToDisplay = "Tax record"
Next HLink
End If

End Sub

"JayLatimer" wrote:

I have a macro which converts urls in a column to the words "Tax Record" but
the macro will not work. When I run the Macro it prompts for Column and then
prompts for sheet name as expected. When valid inputis given to both
questions the Macro ends without error but does not convert the urls in the
column identified into the words "Tax Record"

I would appreicate any help I can get. The Marco is:

Sub chngelink()
'
' chngelink Macro
'
' Keyboard Shortcut: Ctrl+z
Dim MyCol As String
Dim MySht As String
On Error Resume Next
MyCol = InputBox("Enter column LETTER(S)")
MySht = InputBox("Enter sheet name")
Lastrow = Sheets(MySht).Cells(Cells.Rows.Count, MyCol).End(xlUp).Row
For Each c In Sheets(MySht).Range(MyCol & "2:" & MyCol & Lastrow)
c.Hyperlinks(1).TextToDisplay = "Tax record"
Next
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Macro That doesn't work - Please help

Jay,

I forgot to mention Shortcut Keys in my last post. I would recommend that
you not use native Excel shortcuts as your custom macro shortcut because you
will likely override the native shortcut key when you do so. For example,
Ctrl+z is the shortcut key for Undo, and rather than getting Undo when you
use Ctrl+z, you'll get your macro.

There is a whole host of shortcut keys in Excel, but some common Ctrl+
shortcut keys are as follows: Ctrl+ z, x, c, v, b, n, a, s, d, f, g, h, w,
r, u, i, o, p, and 1.

Best,

Matthew Herbert

"JayLatimer" wrote:

I have a macro which converts urls in a column to the words "Tax Record" but
the macro will not work. When I run the Macro it prompts for Column and then
prompts for sheet name as expected. When valid inputis given to both
questions the Macro ends without error but does not convert the urls in the
column identified into the words "Tax Record"

I would appreicate any help I can get. The Marco is:

Sub chngelink()
'
' chngelink Macro
'
' Keyboard Shortcut: Ctrl+z
Dim MyCol As String
Dim MySht As String
On Error Resume Next
MyCol = InputBox("Enter column LETTER(S)")
MySht = InputBox("Enter sheet name")
Lastrow = Sheets(MySht).Cells(Cells.Rows.Count, MyCol).End(xlUp).Row
For Each c In Sheets(MySht).Range(MyCol & "2:" & MyCol & Lastrow)
c.Hyperlinks(1).TextToDisplay = "Tax record"
Next
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default Macro That doesn't work - Please help

try this

Option Explicit
Sub chngelinkSAS()
Dim lastrow As Long
Dim i As Long
Dim MyCol As String
Dim MySht As String
On Error Resume Next
MyCol = InputBox("Enter column LETTER(S)")
MySht = InputBox("Enter sheet name")
Sheets(MySht).Select
lastrow = Sheets(MySht) _
..Cells(Cells.Rows.Count, MyCol).End(xlUp).Row
For i = 2 To lastrow
ActiveSheet.Hyperlinks.Add Anchor:=Cells(i, MyCol), _
Address:=Cells(i, MyCol).Hyperlinks(1).Address, _
TextToDisplay:="Tax Record"
Next i
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"JayLatimer" wrote in message
...
I have a macro which converts urls in a column to the words "Tax Record"
but
the macro will not work. When I run the Macro it prompts for Column and
then
prompts for sheet name as expected. When valid inputis given to both
questions the Macro ends without error but does not convert the urls in
the
column identified into the words "Tax Record"

I would appreicate any help I can get. The Marco is:

Sub chngelink()
'
' chngelink Macro
'
' Keyboard Shortcut: Ctrl+z
Dim MyCol As String
Dim MySht As String
On Error Resume Next
MyCol = InputBox("Enter column LETTER(S)")
MySht = InputBox("Enter sheet name")
Lastrow = Sheets(MySht).Cells(Cells.Rows.Count, MyCol).End(xlUp).Row
For Each c In Sheets(MySht).Range(MyCol & "2:" & MyCol & Lastrow)
c.Hyperlinks(1).TextToDisplay = "Tax record"
Next
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
Macro to sum doesn't work RM270 Excel Discussion (Misc queries) 2 March 17th 10 05:55 PM
Macro to update a column in a work based on another work sheet WickerMan New Users to Excel 1 December 4th 09 12:58 PM
Macro works Macro does not work Wanna Learn Excel Discussion (Misc queries) 4 March 24th 08 12:51 PM
If I have a work sheet protected and try to run a macro to hide rows or columns it won't work. Correct? Marc Excel Programming 2 July 12th 06 04:10 AM
Why does the macro not work? Xanadude Excel Worksheet Functions 4 April 24th 05 09:06 PM


All times are GMT +1. The time now is 06:10 PM.

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

About Us

"It's about Microsoft Excel"