dcsimg
Results 1 to 8 of 8

Thread: Problem copying the content of a named range, to another named range

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2018
    Posts
    6

    Question Problem copying the content of a named range, to another named range

    Greetings!

    I have two named cells, that are a SINGLE cell each on the same worksheet.
    res_Info and res_InfoSource

    In VBA, I need to copy the res_Source, to res_Info. I have been using this without issues... until now:
    I am getting the Application-defined or object-defined error Number: 1004 error. If I remove a SINGLE character from res_InfoSource, it works! So I am guessing there is a maximum amount of characters that can be copied in this way?!? I estimate the size of res_InfoSource to be about 8k of information (about 2 pages of text)

    Code:
    Application.ThisWorkbook.Names("res_Info").RefersToRange = Application.ThisWorkbook.Names("res_InfoSource").RefersToRange
    Is there a better way to do this, without incurring any size limits on the named ranges? Or perhaps an alternative that wouldn't cause the 1004 error?

    THANKS!!!

  2. #2

    Thread Starter
    New Member
    Join Date
    Nov 2018
    Posts
    6

    Re: Problem copying the content of a named range, to another named range

    Oh I forgot to mention: I am working on Excel 2007. I tried on Excel 2013, but I saw the same behavior/error!

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,819

    Re: Problem copying the content of a named range, to another named range

    you should consider other options, even if this issue is resolved, having 8K in a single cell is likely to give other problems sooner or later

    according to a quick search, the max characters in a cell is 32,767, how close to that are you getting?
    even in later versions larger amounts of text may not raise an error but the additional text will be discarded
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2018
    Posts
    6

    Re: Problem copying the content of a named range, to another named range

    (hmm duplicated post.. please ignore/delete!)
    Last edited by mikkie98; Nov 9th, 2018 at 11:24 AM. Reason: duplicate

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2018
    Posts
    6

    Re: Problem copying the content of a named range, to another named range

    I believe I've hit this limit, as per the excel specifications:
    Length of formula contents 8,192 characters

    I would be quite interested in hearing alternatives.

    Basically, I have a bunch of stuff that come together in the named range res_InfoSource. If I would just use the named cell by itself, I have no issues. BUT I am attempting to apply some BOLD font to sections titles (code from here) to this big block of text to make it more readable. But I cannot apply the BOLD to my source text, as the user might want to keep it 'as is' (i.e. not use bold). Hence why res_Source is copied to another cell before processing the application of BOLD (which, if you ask, I am doing using <B>Text Here</B>)

    Currently, this works pretty good... until res_InfoSource exceeds a certain size (which I now believe to be 8k as per my research online)

    QUERY: If I would split my source (res_InfoSource named cell) in multiple (read smaller) parts, would it be possible to assemble these parts into a single cell, so I could then apply the Bold? How would I go about doing this? I'll go play around with it to see if I can find a solution, but any/all help is quite welcomed!

    THANKS!

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    3,834

    Re: Problem copying the content of a named range, to another named range

    Quote Originally Posted by mikkie98 View Post
    Basically, I have a bunch of stuff that come together in the named range res_InfoSource.
    If your res_InfoSource is a Named-Range, referring to a single cell, then why not write a simple:
    Public Function MyBoldFormatter(ByVal strInput As String) As String
    ...in a VBA-Module for it?

    This way you would not have to "make a copy" of the Source-Range -
    instead all you have to write into your "formatted Target-Cell" would be your new Function-Call:
    = MyBoldFormatter(res_InfoSource)

    Olaf
    Last edited by Schmidt; Nov 9th, 2018 at 12:11 PM.

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2018
    Posts
    6

    Re: Problem copying the content of a named range, to another named range

    Quote Originally Posted by Schmidt View Post
    If your res_InfoSource is a Named-Range, referring to a single cell, then why not write a simple
    (global) MyBoldFormatter()-Function in a VBA-Module for it?

    This way you would not have to "make a copy" of the Source-Range -
    instead all you have to write into your "formatted Target-Cell" would be your new Function-Call:
    = MyBoldFormatter(res_InfoSource)

    Olaf
    Yes, res_InfoSource is a single cell named range.

    It pull lots of data all over, which contain text that is formatted with <B> and </B> tags (to define where to apply Bold). This needs to be parsed. If the user does not want the Bold text, these are removed with SUBSTITUTE(). If the user wants the Bold text, this is where the copy of the res_InfoSource occurs (to res_Info) and afterwards, a VBA function is called in to apply the bold in res_Info (as per the link I provided in a previous post). This basically removes the <B> and </B> and any text between those tags are 'bolded'.

    I am not certain how I can do it otherwise, and I don't understand how your suggestion can be applied...

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2018
    Posts
    6

    Re: Problem copying the content of a named range, to another named range

    ok after playing around some more, I found that this works:

    Application.ThisWorkbook.Names("res_Info").RefersToRange = CStr(Application.ThisWorkbook.Names("res_InfoSource").RefersToRange)

    I am guessing that being a string, the cell can now contain 32k of information, as opposed to the 8k for a formula... Right!?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width