Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-31-2023, 08:02 PM
soroush.kalantari soroush.kalantari is offline Error when hyperlinking Excel cells to worksheets based on the cell values for sheets whose name  in Windows 10 Error when hyperlinking Excel cells to worksheets based on the cell values for sheets whose name  in Office 2016
Competent Performer
Error when hyperlinking Excel cells to worksheets based on the cell values for sheets whose name  in
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default Error when hyperlinking Excel cells to worksheets based on the cell values for sheets whose name in

I have written following macro to hyperlink Excel cells to worksheets based on the cell value. It failes to work for sheets whose name include “-“. (See cell A4 in the excel attachment.)
Can you guide me on this issue?




Sub FShyeperlink()
On Error Resume Next



Dim n As Integer
Dim i As Integer
Dim rng As Range
n = Selection.Rows.Count
Set rng = Selection
Selection.Hyperlinks.Delete
For i = 1 To n


rng(i).Select

ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
Selection.Value & "!A1"
Next i
End Sub
Attached Files
File Type: xlsm sheethyperlink.xlsm (18.6 KB, 2 views)
Reply With Quote
  #2  
Old 08-01-2023, 02:32 AM
p45cal's Avatar
p45cal p45cal is offline Error when hyperlinking Excel cells to worksheets based on the cell values for sheets whose name  in Windows 10 Error when hyperlinking Excel cells to worksheets based on the cell values for sheets whose name  in Office 2021
Expert
 
Join Date: Apr 2014
Posts: 871
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

Change to:
Code:
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:="'" & Selection.Value & "'!A1"
but you could try this instead:
Code:
Sub FShyeperlink()
Dim cll As Range
'On Error Resume Next' only use this if you need it.
For Each cll In Selection.Cells
  cll.Hyperlinks.Delete
  cll.Parent.Hyperlinks.Add Anchor:=cll, Address:="", SubAddress:="'" & cll.Value & "'!A1"
Next cll
End Sub
Reply With Quote
  #3  
Old 08-01-2023, 11:01 PM
soroush.kalantari soroush.kalantari is offline Error when hyperlinking Excel cells to worksheets based on the cell values for sheets whose name  in Windows 10 Error when hyperlinking Excel cells to worksheets based on the cell values for sheets whose name  in Office 2016
Competent Performer
Error when hyperlinking Excel cells to worksheets based on the cell values for sheets whose name  in
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default

Quote:
Originally Posted by p45cal View Post
Change to:
Code:
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:="'" & Selection.Value & "'!A1"
but you could try this instead:
Code:
Sub FShyeperlink()
Dim cll As Range
'On Error Resume Next' only use this if you need it.
For Each cll In Selection.Cells
  cll.Hyperlinks.Delete
  cll.Parent.Hyperlinks.Add Anchor:=cll, Address:="", SubAddress:="'" & cll.Value & "'!A1"
Next cll
End Sub
Thank you very much. Your reply solved the problem and learned me some new things about making my codes more concise and optimum.
Reply With Quote
Reply

Tags
hyperlink



Similar Threads
Thread Thread Starter Forum Replies Last Post
Merging 2 different cells containing IF formula & change in cell values based on multiple time frame jay_excel Excel 0 07-29-2017 11:04 PM
Error when hyperlinking Excel cells to worksheets based on the cell values for sheets whose name  in copy cells from a worksheet into other worksheets based on Criteria Elton Wolter Excel Programming 4 04-16-2016 08:44 AM
Error when hyperlinking Excel cells to worksheets based on the cell values for sheets whose name  in Column B Cell 25 of all worksheets copies data found in the lower cells ... rpcalo Excel 3 03-10-2016 03:38 AM
Error when hyperlinking Excel cells to worksheets based on the cell values for sheets whose name  in Reference another workbook and return values from the same cell across multiple sheets/tabs lwls Excel Programming 5 11-08-2014 02:11 PM
Change values in cells based on criteria SaneMan Excel Programming 2 02-02-2012 07:58 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft