SOLVED
Home

Issue with hyperlink formula when a space character is in the destination worksheet name

%3CLINGO-SUB%20id%3D%22lingo-sub-354309%22%20slang%3D%22en-US%22%3EIssue%20with%20hyperlink%20formula%20when%20a%20space%20character%20is%20in%20the%20destination%20worksheet%20name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-354309%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20using%20the%20following%20formula%20to%20create%20a%20hyperlink%20to%20another%20worksheet%20in%20the%20same%20workbook.%26nbsp%3B%20The%20formula%20parses%20out%20the%20destination%20worksheet%20from%20another%20cell%20(A12%20in%20the%20example%20below)%20using%20the%20carat%20delimiter.%26nbsp%3B%20The%20formula%20works%20perfectly%20as%20long%20as%20the%20destination%20worksheet%20does%20not%20have%20any%20space%20characters%20in%20the%20worksheet%20name.%26nbsp%3B%20Once%20a%20space%20is%20added%20in%20a%20worksheet%20name%20then%20the%20formula%20fails%20(with%20%22Reference%20isn't%20valid.%22).%26nbsp%3B%20I've%20tried%20escaping%20the%20double%20quotes%20in%20the%20formula%20and%20I've%20tried%20substituting%20the%20space%20character%20with%20CHAR(32)%2C%20but%20either%20that's%20wrong%20or%20I'm%20screwing%20up%20the%20implementation.%26nbsp%3B%20I'd%20appreciate%20any%20help%20in%20fixing%20the%20formula.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance%2C%3C%2FP%3E%3CP%3EAndrew%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DIFERROR(HYPERLINK(%22%23%22%26amp%3BMID(%24A12%2CFIND(CHAR(1)%2CSUBSTITUTE(%24A12%2C%22%5E%22%2CCHAR(1)%2C11))%2B1%2C50)%26amp%3B%22!a1%22%2CMID(%24A12%2CFIND(CHAR(1)%2CSUBSTITUTE(%24A12%2C%22%5E%22%2CCHAR(1)%2C11))%2B1%2C50))%2C%22%22)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-354309%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-354725%22%20slang%3D%22en-US%22%3ERe%3A%20Issue%20with%20hyperlink%20formula%20when%20a%20space%20character%20is%20in%20the%20destination%20worksheet%20name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-354725%22%20slang%3D%22en-US%22%3E%3CP%3EAbsolutely%20I%20learned%20something.%26nbsp%3B%20And%20I%20agree%2C%20dynamic%20is%20preferred.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-354713%22%20slang%3D%22en-US%22%3ERe%3A%20Issue%20with%20hyperlink%20formula%20when%20a%20space%20character%20is%20in%20the%20destination%20worksheet%20name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-354713%22%20slang%3D%22en-US%22%3EI%20agree%20with%20your%20contention%2C%20which%20is%20for%20your%20exclusive%20use.%20For%20the%20sake%20of%20those%20who%20viewed%20this%20thread%20who%20may%20have%20a%20similar%2C%20but%20not%20exactly%20the%20same%2C%20situation%20to%20yours%2C%20my%20dynamic%20formula%20prevails.%20Anyway%2C%20I%20hope%20you%20somehow%20learned%20something%20from%20me.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-354682%22%20slang%3D%22en-US%22%3ERe%3A%20Issue%20with%20hyperlink%20formula%20when%20a%20space%20character%20is%20in%20the%20destination%20worksheet%20name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-354682%22%20slang%3D%22en-US%22%3E%3CP%3EAh.%26nbsp%3B%20I%20could%20see%20the%20value%20of%20it%20being%20dynamic%20if%20all%20my%20other%20parsing%20were%20dynamic.%26nbsp%3B%20But%20you'll%20note%20that%20I%20have%2012%20elements%20in%20the%20string.%26nbsp%3B%20The%20worksheet%20name%20only%20happens%20to%20be%20the%20last.%26nbsp%3B%20I%20could%20search%20for%20the%20nth%20instance%20of%20the%20carat%20to%20make%20the%20formula%20dynamic%20for%20all%20the%20parsing%20from%20the%20middle%2C%20but%20the%20the%20string%20isn't%20ever%20going%20to%20change%20so%20I%20just%20didn't%20see%20the%20value%20of%20bothering%20(or%20making%20the%20formula%20longer).%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-354653%22%20slang%3D%22en-US%22%3ERe%3A%20Issue%20with%20hyperlink%20formula%20when%20a%20space%20character%20is%20in%20the%20destination%20worksheet%20name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-354653%22%20slang%3D%22en-US%22%3EYour%20formula%20is%20shorter%20because%2011%2C%20which%20is%20the%20last%20instance%20of%20the%20circumflex%20accent%20(%5E)%2C%20is%20hard-coded.%20Thus%2C%20your%20formula%20is%20not%20dynamic.%20Conversely%2C%20my%20formula%20dynamically%20calculates%20such%20last%20instance.%3CBR%20%2F%3EAlso%2C%2031%20is%20hard-coded%20in%20your%20formula%20but%20I%20won%E2%80%99t%20object%20to%20that%20because%20the%20maximum%20length%20of%20a%20Sheet%20Name%20is%20nonetheless%2031%20characters.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-354640%22%20slang%3D%22en-US%22%3ERe%3A%20Issue%20with%20hyperlink%20formula%20when%20a%20space%20character%20is%20in%20the%20destination%20worksheet%20name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-354640%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20Twifoo.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat's%20a%20clever%20implementation%20substituting%20the%20carat%20for%20the%20pipe%20to%20get%20the%20location%20of%20the%20last%20carat.%26nbsp%3B%20But%20I'm%20wondering%20what%20does%20it%20get%20me%20beyond%20using%20the%20MID%20function%20to%20parse%20out%20the%20worksheet%20name%3F%26nbsp%3B%20Just%20inserting%20the%20single%20quotes%20into%20my%20existing%20formula%20is%20shorter.%26nbsp%3B%20Am%20I%20missing%20something%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPS.%20After%20your%20first%20post%20I%20tried%20using%20single%20quotes%2C%20but%20I%20put%20the%20second%20one%20after%20the%20exclamation%20mark%20instead%20of%20before.%26nbsp%3B%20Doh!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20works%20too%3A%3C%2FP%3E%3CP%3E%3DHYPERLINK(%22%23'%22%26amp%3BMID(%24A12%2CFIND(CHAR(1)%2CSUBSTITUTE(%24A12%2C%22%5E%22%2CCHAR(1)%2C11))%2B1%2C31)%26amp%3B%22'!A1%22%2CMID(%24A12%2CFIND(CHAR(1)%2CSUBSTITUTE(%24A12%2C%22%5E%22%2CCHAR(1)%2C11))%2B1%2C31))%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-354398%22%20slang%3D%22en-US%22%3ERe%3A%20Issue%20with%20hyperlink%20formula%20when%20a%20space%20character%20is%20in%20the%20destination%20worksheet%20name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-354398%22%20slang%3D%22en-US%22%3EHi%20Andrew%2C%3CBR%20%2F%3EAssuming%20your%20destination%20cell%20is%20A1%2C%20your%20hyperlink%20formula%20is%3A%3CBR%20%2F%3E%3DHYPERLINK(%22%23'%22%26amp%3BRIGHT(A12%2C%3CBR%20%2F%3ELEN(A12)-FIND(%22%7C%22%2CSUBSTITUTE(A12%2C%22%5E%22%2C%22%7C%22%2C%3CBR%20%2F%3ELEN(A12)-LEN(SUBSTITUTE(A12%2C%22%5E%22%2C%22%22)))))%26amp%3B%22'!A1%22%2C%22Link%22)%3CBR%20%2F%3ETo%20be%20safe%2C%20always%20enclose%20the%20Sheet%20Name%20in%20single%20quotes%20(')%20whether%20or%20not%20such%20Name%20includes%20a%20space.%3CBR%20%2F%3ECheers!%3CBR%20%2F%3ETwifoo%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-354372%22%20slang%3D%22en-US%22%3ERe%3A%20Issue%20with%20hyperlink%20formula%20when%20a%20space%20character%20is%20in%20the%20destination%20worksheet%20name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-354372%22%20slang%3D%22en-US%22%3E%3CP%3EA12%20is%20a%20formula.%26nbsp%3B%20Below%20is%20the%20value%3A%3C%2FP%3E%3CP%3EPower%5ESmart-UPS%20-%206000VA%20-%20208V%20to%20208%20-%204%20OUTPUT%20%2F%201%20INPUT%20-%206%20RU%5ECyberpower%20%5EOL6KRT3UTAA%5E1%5E2014%5E8%5E2022%5E5652%5E0.03%5E7160%5ESH%20110%20Main%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20destination%20worksheet%20is%3A%3C%2FP%3E%3CP%3ESH%20110%20Main%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-354369%22%20slang%3D%22en-US%22%3ERe%3A%20Issue%20with%20hyperlink%20formula%20when%20a%20space%20character%20is%20in%20the%20destination%20worksheet%20name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-354369%22%20slang%3D%22en-US%22%3EHello%20Andrew%2C%3CBR%20%2F%3EPlease%20specify%20the%20value%20of%20A12%20and%20the%20destination%20of%20your%20hyperlink.%20Note%20that%20the%20Sheet%20Name%20must%20be%20enclosed%20in%20single%20quotes%20(')%20whenever%20it%20includes%20a%20space.%3C%2FLINGO-BODY%3E
Highlighted
Andrew Lindsay
Occasional Contributor

I'm using the following formula to create a hyperlink to another worksheet in the same workbook.  The formula parses out the destination worksheet from another cell (A12 in the example below) using the carat delimiter.  The formula works perfectly as long as the destination worksheet does not have any space characters in the worksheet name.  Once a space is added in a worksheet name then the formula fails (with "Reference isn't valid.").  I've tried escaping the double quotes in the formula and I've tried substituting the space character with CHAR(32), but either that's wrong or I'm screwing up the implementation.  I'd appreciate any help in fixing the formula.

 

Thanks in advance,

Andrew

 

=IFERROR(HYPERLINK("#"&MID($A12,FIND(CHAR(1),SUBSTITUTE($A12,"^",CHAR(1),11))+1,50)&"!a1",MID($A12,FIND(CHAR(1),SUBSTITUTE($A12,"^",CHAR(1),11))+1,50)),"")

8 Replies
Hello Andrew,
Please specify the value of A12 and the destination of your hyperlink. Note that the Sheet Name must be enclosed in single quotes (') whenever it includes a space.

A12 is a formula.  Below is the value:

Power^Smart-UPS - 6000VA - 208V to 208 - 4 OUTPUT / 1 INPUT - 6 RU^Cyberpower ^OL6KRT3UTAA^1^2014^8^2022^5652^0.03^7160^SH 110 Main

 

The destination worksheet is:

SH 110 Main

 

Thanks.

Solution
Hi Andrew,
Assuming your destination cell is A1, your hyperlink formula is:
=HYPERLINK("#'"&RIGHT(A12,
LEN(A12)-FIND("|",SUBSTITUTE(A12,"^","|",
LEN(A12)-LEN(SUBSTITUTE(A12,"^","")))))&"'!A1","Link")
To be safe, always enclose the Sheet Name in single quotes (') whether or not such Name includes a space.
Cheers!
Twifoo

Thanks Twifoo.

 

That's a clever implementation substituting the carat for the pipe to get the location of the last carat.  But I'm wondering what does it get me beyond using the MID function to parse out the worksheet name?  Just inserting the single quotes into my existing formula is shorter.  Am I missing something?

 

PS. After your first post I tried using single quotes, but I put the second one after the exclamation mark instead of before.  Doh!

 

This works too:

=HYPERLINK("#'"&MID($A12,FIND(CHAR(1),SUBSTITUTE($A12,"^",CHAR(1),11))+1,31)&"'!A1",MID($A12,FIND(CHAR(1),SUBSTITUTE($A12,"^",CHAR(1),11))+1,31))

Your formula is shorter because 11, which is the last instance of the circumflex accent (^), is hard-coded. Thus, your formula is not dynamic. Conversely, my formula dynamically calculates such last instance.
Also, 31 is hard-coded in your formula but I won’t object to that because the maximum length of a Sheet Name is nonetheless 31 characters.

Ah.  I could see the value of it being dynamic if all my other parsing were dynamic.  But you'll note that I have 12 elements in the string.  The worksheet name only happens to be the last.  I could search for the nth instance of the carat to make the formula dynamic for all the parsing from the middle, but the the string isn't ever going to change so I just didn't see the value of bothering (or making the formula longer).

I agree with your contention, which is for your exclusive use. For the sake of those who viewed this thread who may have a similar, but not exactly the same, situation to yours, my dynamic formula prevails. Anyway, I hope you somehow learned something from me.

Absolutely I learned something.  And I agree, dynamic is preferred.

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
30 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies