Exceeding Max Char Limit in Excel

后端 未结 11 1638
名媛妹妹
名媛妹妹 2020-12-10 06:51

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

相关标签:
11条回答
  • 2020-12-10 07:36

    You might be out of luck. It seems that the character limit for hyperlinks in Excel is 256 as pointed out here. If you test it out yourself (I have Excel 2007, too), =HYPERLINK(REPT("a",255)) works and =HYPERLINK(REPT("a",256)) does not and throws a #VALUE! error.

    0 讨论(0)
  • 2020-12-10 07:37

    Guys I think a URL Shortening VBA will help you. Here is one which I found today. It works like a charm: http://www.jpsoftwaretech.com/shorten-urls-with-bit-ly-web-api-and-vba/

    0 讨论(0)
  • 2020-12-10 07:39

    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.

    0 讨论(0)
  • 2020-12-10 07:45

    Here's some VBA which uses bitly.com to shorten a URL. It is based on the bitly API documentation.

    1. Create a free account on bitly.
    2. Valid email address with bitly.
    3. Get access token from bitly.
    4. Substitute the access token in the VBA code below where it says MY_TOKEN.
    5. Copy and paste the code in Excel's VBA.
    6. In a cell, write the following '=Hyperlink(GetURL("some really long URL"))' without single quote ' marks. Note: Instead of passing a string to GetURL(), pass a reference to a cell which has a URL in it as text.
    Public Function GetURL(longUrl As String) As String
      Dim xml As Object
    
      longUrl = URLEncode(longUrl)
      Set xml = CreateObject("MSXML2.XMLHTTP.6.0")
    
      xml.Open "GET", "https://api-ssl.bitly.com/v3/shorten?format=xml&access_token=MY_TOKEN=" & longUrl, False
      xml.Send
    
      GetURL = xml.responsetext
    
      head = InStr(GetURL, "<url>") + 5
      tail = InStr(GetURL, "</url>")
    
      GetURL = Mid(GetURL, head, tail - head)
    
    End Function
    
    Function URLEncode(ByVal Text As String) As String
      Dim i As Integer
      Dim acode As Integer
      Dim char As String
      URLEncode = Text
      For i = Len(URLEncode) To 1 Step -1
        acode = Asc(Mid$(URLEncode, i, 1))
        Select Case acode
          Case 48 To 57, 65 To 90, 97 To 122
            ' don't touch alphanumeric chars
          Case 32
            ' replace space with "+"
            Mid$(URLEncode, i, 1) = "+"
          Case Else
            ' replace punctuation chars with "%hex"
            URLEncode = Left$(URLEncode, i - 1) & "%" & Hex$(acode) & Mid$(URLEncode, i + 1)
        End Select
      Next
    End Function
    
    0 讨论(0)
  • 2020-12-10 07:47

    You can use the VBA Shell() routine to execute a browser and pass the URL to it on the command line passed via the Shell() call. Thus the URL can be any length supported by the shell mechanism.

    Furthermore you can get this URL from any cell value by having the user double-click that cell. This value can be constructed from many cells via a single CONCATENATE() function call! That's right: just a single call. The CONCATENATE() will take a large number of parameters and will create a string well-bigger than 255 characters. You don't need to laboriously join many separate concatenations or use loads of "builder" cells. One will do!

    The macro needs to be created by opening the VIEW CODE option when you right-click the tab at the bottom of the worksheet. Then write the following phenomenally short, simple and painless bit of code:

    Option Explicit             
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)               
       If Selection.Count = 1 Then              
          If Left(Target.Value, 7) = "HTTP://" Then             
             Cancel = True              
             Shell ("""" + Range("Browser").Value + """" + " " + """" + Target.Value + """")                
          End If                
       End If               
    End Sub     
    

    Note that "Browser" is a named cell that should contain the unquoted path of your browser, be that IE, Opera, Mozilla or Chrome. You have to name the cell yourself, or change the macro to have a hard cell reference like "A2". And of course, that cell value must be a valid browser path!

    Once you have all of this in place, you can double-click ANY cell that has a value starting with the text "HTTP://" and Excel will open the browser with that full value, no-matter how long it is. All you then need is to build your string in that cell and perhaps format it colour/font-wise to make it obvious that it is a hyperlink cell to be double-clicked. A textual hint nearby may also be in order!

    Incidentally, an alternative to the Shell() line in the macro is:

    ThisWorkbook.FollowHyperlink Address:=Target.Value 
    

    Whilst this will also process URLs bigger than 255 characters, I found that this FollowHyperlink() function causes the URL to be sent TWICE. Once by the Excel function itself (presumably to test it) and then again by the default browser that Excel opens! This may not be desirable (and wasn't in my case). This is why I ended up using the Shell() function instead.

    0 讨论(0)
提交回复
热议问题