Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Exceeding Max Char Limit in Excel




How do I use more than 255 characters in Excel's CONCATENATE function? I am actually also using the CONCATENATE function within the HYPERLINK function in EXCEL. An example looks like this:

=HYPERLINK(CONCATENATE("http://www.google/com/morethan255charsmorethan255charsmorethan255charsmorethan255charsmorethan255charsmorethan255charsmorethan255charsmorethan255charsmorethan255charsmorethan255chars","morethan255chars morethan255charsmorethan255charsmorethan255charsmorethan25"),"link");

UPDATE: It's not issue with CONCATENATE function, but an issue with the first parameter of the HYPERLINK function. Using a string longer than 255 characters directly/indirectly (ex: =HYPERLINK(K204,"link") where K204 contains the 256-character length link) fails the HYPERLINK function

I realize that I can use a URL shortener, but I am doing this for ALOT of links which would require ALOT of manual use of the URL shortener.

like image 743
syker Avatar asked Oct 08 '10 19:10


People also ask

How do I bypass 255 character limit in Excel?

Text values in formulas are limited to 255 characters. To create text values longer than 255 characters in a formula, use the CONCATENATE function or the concatenation operator (&).

Is there a character limit per cell in Excel?

Information about maximum characters count in an Excel cellAn Excel cell accepts only maximum 32767 characters. ArgumentOutOfRangeException is thrown when you try to set the text with length greater that 32767 characters, into an Excel cell.

How do you fix the maximum length of cell contents text is 32767 characters?

Your best option would be switching the export to CSV . That is the maximum number of characters allowed in the excel cell value. Truncate the characters if it is more than 32676.

2 Answers

UPDATE: Because of Karls comment I revisited my answer an found out, that Excel 2007 does not seem to allow User Defined Functions to set hyperlinks anymore (quite sensibly, see my own comment in the code). So the original code (below the line) does not work in more recent versions of Excel (I haven't tested Excel 2010 but I assume the result is the same). For historical reasons I do not delete the old code (an editor might think otherwise -- feel free to edit/ delete accordingly).

So what remains is to set long hyperlinks programatically, e.g.

Sub insertVeryLongHyperlink()

    Dim curCell As Range
    Dim longHyperlink As String

    Set curCell = Range("A1")   ' or use any cell-reference
    longHyperlink = "http://www.veryLongURL.com/abcde"  ' Or a Cell reference like [C1]

    curCell.Hyperlinks.Add Anchor:=curCell, _
                    Address:=longHyperlink, _
                    SubAddress:="", _
                    ScreenTip:=" - Click here to follow the hyperlink", _
                    TextToDisplay:="Long Hyperlink"

End Sub

What follows does not work in Excel 2010 anymore; see my comment above

The "copy the hyperlink from Word and paste into Excel" got me thinking. So obviously the limit is both in the built-in HYPERLINK-function and in the dialog-window 'edit hyperlink'. On the other hand it should be -- and actually is -- possible to set longer hyperlinks via VBA.

This code does not work in Excel 2010 anymore

Function myHyperlink(cell As Range, _
                        hyperlinkAddress As String, _
                        Optional TextToDisplay As Variant, _
                        Optional ScreenTip As Variant)

    ' Inserts a Hyperlink
    '   at the position     cell (this should be the position where the UDF is used,
    '                       since the return value of the UDF is = TextToDisplay)
    '   with the            hyperlinkAddress
    '   optional            TextToDisplay
    '   optional            ScreenTip

    ' #######################################
    ' Warning Warning Warning Warning Warning
    ' #######################################

    ' 1) Since it is really bad practice to have a function perform procedural
    '    tasks, you should not do this.
    ' 2) You have no garantee, the link is updated when the value hyperlinkAddress changes


    ' If more than one cell is selected as target range,
    ' use the top left cell
    Set cell = cell.Resize(1, 1)

    If IsMissing(TextToDisplay) Then
        TextToDisplay = hyperlinkAddress
    End If

    If IsMissing(ScreenTip) Then
        ScreenTip = hyperlinkAddress & " - Click here to follow the hyperlink"
    End If

    cell.Hyperlinks.Add Anchor:=ActiveCell, _
                        Address:=hyperlinkAddress, _
                        SubAddress:="", _
                        ScreenTip:=ScreenTip, _

    ' There doesn't seem to be another way to set TextToDisplay
    myHyperlink = TextToDisplay

End Function

Use as a normal Excel-function, but be sure to add the current cell as first parameter (i.e. the following formula is inserted in cell A1)

=myHyperlink(A1,B1,"TextToDisplay", "ScreenTip")

You can neither pull the formula down nor copy it to another cell. If you do that you have to let the formula be recalculated (neither ALT-CTRL-F9 nor ALT-CTRL-SHIFT-F9 as force recalculate seem to work) so go into each cell, press F2 to activate it and finish with Return.

I hope I am not helping you to screw up too many Excel-Workbooks.

It is probably safer to write an VBA that is explicitly started that iterates through a list and writes to hyperlinks. That way they can reused and there are no functions.

Regards Andreas

like image 63
Andreas J Avatar answered Sep 22 '22 07:09

Andreas J

I have Excel 2007 and I tried making a cell with 300 characters in A1, and another with 300 different characters in B1.

Then I made C1 = CONCATENATE(A1, B1).

I can see all of the characters from both cells. Nothing is missing or truncated and no errors were received. It looks good to me.

What makes you think that the concatenate is failing? Are you having trouble seeing your results? If your cell contains more than 1,024 characters only the first 1,024 are displayed in the cell. However they are still there and if you copy and paste them all of the characters will be copied.

Edit: Now that you have editted your question I realize the problem is with HYPERLINK and not CONCATENATE.

The only way to get around the 255 character limit of HYPERLINK formula in Excel is to copy a hyperlink from Word and paste it into a cell in Excel. Then it can be super long. I know this is an unreasonable manual process if you have a lot of links but it seems the only way to get it into an Excel spreadsheet and yet still have it be a hyperlink that you can click on and be redirected. If you don't need it to act like a hyperlink then I would suggest rewriting your queries to return the hyperlink as its own text field and then it will be fine.

like image 22
hyprsleepy Avatar answered Sep 20 '22 07:09