just_jon
Legend
- Joined
- Sep 3, 2002
- Messages
- 10,473
There is a simple explanation here, it just escapes me. The code below checks to see if the current selection is in E:E and is a constant. If so, then find a matching value on a second sheet and convert the cell to a hyperlink to that 2nd sheet's cell.
If I comment out the Private sub line and un-comment the next 2, it runs like a champ, but I get Runtime error 13, Type mismatch on the i = Application... line when run as an event macro.
What am I doing wrong?
<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_SelectionChange(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Excel.Range)
<SPAN style="color:#007F00">'Sub foo()</SPAN>
<SPAN style="color:#007F00">'Set Target = [E5]</SPAN>
<SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Intersect(Target, [E:E].SpecialCells(xlCellTypeConstants)) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> WS <SPAN style="color:#00007F">As</SPAN> Worksheet, i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>, CA <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
<SPAN style="color:#00007F">Set</SPAN> WS = Worksheets("Training Log")
i = Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Match(Target.Value, WS.[D:D], 0))
<SPAN style="color:#00007F">If</SPAN> (i) <SPAN style="color:#00007F">Then</SPAN>
CA = Application.WorksheetFunction.Index(WS.[D:D], _
Application.WorksheetFunction.Match(Target.Value, WS.[D:D], 0), 0).Address
Target.Formula = "=HYPERLINK(""[" & ActiveWorkbook.Name & "]'Training Log'!" & CA & """,""" & CA & """)"
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">Set</SPAN> WS = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
As always, thanks for looking!
If I comment out the Private sub line and un-comment the next 2, it runs like a champ, but I get Runtime error 13, Type mismatch on the i = Application... line when run as an event macro.
What am I doing wrong?
<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_SelectionChange(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Excel.Range)
<SPAN style="color:#007F00">'Sub foo()</SPAN>
<SPAN style="color:#007F00">'Set Target = [E5]</SPAN>
<SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Intersect(Target, [E:E].SpecialCells(xlCellTypeConstants)) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> WS <SPAN style="color:#00007F">As</SPAN> Worksheet, i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>, CA <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
<SPAN style="color:#00007F">Set</SPAN> WS = Worksheets("Training Log")
i = Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Match(Target.Value, WS.[D:D], 0))
<SPAN style="color:#00007F">If</SPAN> (i) <SPAN style="color:#00007F">Then</SPAN>
CA = Application.WorksheetFunction.Index(WS.[D:D], _
Application.WorksheetFunction.Match(Target.Value, WS.[D:D], 0), 0).Address
Target.Formula = "=HYPERLINK(""[" & ActiveWorkbook.Name & "]'Training Log'!" & CA & """,""" & CA & """)"
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">Set</SPAN> WS = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
As always, thanks for looking!