Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

excel - workaround named range character limit

I'm building a graph, where the series are named ranges. It all works fine as I have a dropbox, where I select the customer, and it loops through the data, creating the string for the named range and edits it, refresh the graph, voila!

Now, the problem is that it seems I have a limit of 255 characters for this string, and if a customer has a lot of records, then it errors.

Has anyone come across a similar issue or knows a workaround?

For i = 8 To lRow
    If Sheets("Data").Cells(i, 4).Value = cmbInst.Value Then
        nRangeTrade = nRangeTrade & "Data!$A$" & i & ","
        nRangeSettle = nRangeSettle & "Data!$C$" & i & ","
    End If
Next

Value of nRangeTrade :

Data!$A$85,Data!$A$97,Data!$A$98,Data!$A$156,Data!$A$157,Data!$A$308,Data!$A$309,Data!$A$464,Data!$A$473,Data!$A$474,Data!$A$478,Data!$A$490,Data!$A$541,Data!$A$546,Data!$A$633,Da"

as you can see, this is where the problems kick in.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How about something like this

Sub test()
Dim nRangeTrade As Range, nRangeSettle As Range
lrow = 1000
For i = 8 To lrow
    If Sheets("Data").Cells(i, 4).Value = cmbInst.Value Then

        If nRangeTrade Is Nothing Then
            Set nRangeTrade = Sheets("Data").Range("A" & i)
        Else
            Set nRangeTrade = Application.Union(nRangeTrade, Sheets("Data").Range("A" & i))
        End If

        If nRangeSettle Is Nothing Then
            Set nRangeSettle = Sheets("Data").Range("C" & i)
        Else
            Set nRangeSettle = Application.Union(nRangeSettle, Sheets("Data").Range("C" & i))
        End If
    End If
Next i
'nRangeTrade.Select
Sheets("Data").Names.Add Name:="nRangeTrade", RefersTo:=nRangeTrade
Sheets("Data").Names.Add Name:="nRangeSettle", RefersTo:=nRangeSettle
End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...