+ Reply to Thread
Results 1 to 4 of 4

Unable to incorporate a recorded code in a bigger code

  1. #1
    Forum Contributor
    Join Date
    11-11-2012
    Location
    Muscat, Oman
    MS-Off Ver
    Office 365
    Posts
    522

    Unable to incorporate a recorded code in a bigger code

    Hi,

    I am facing a problem with incorporating a recorded code in another code.

    When I paste the recorded code in my main code I get run time error 1004.

    Recorder gave me the code below
    Please Login or Register  to view this content.
    My code looks like :
    Please Login or Register  to view this content.
    Please help.
    VKS

  2. #2
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Unable to incorporate a recorded code in a bigger code

    I believe you are getting the error because the cells would contain a character string that is more than 911 characters upon execution.

    You can take all those If statements and implement them in VBA or distribute some of that logic among multiple cells so that no cell will contain more than 911 characters. I would choose the former solution because the logic will be easier to understand, debug, and extend to other parts of your project.
    <---If my answer helped, please click *

  3. #3
    Forum Contributor
    Join Date
    11-11-2012
    Location
    Muscat, Oman
    MS-Off Ver
    Office 365
    Posts
    522

    Re: Unable to incorporate a recorded code in a bigger code

    Quote Originally Posted by joe31623 View Post
    I believe you are getting the error because the cells would contain a character string that is more than 911 characters upon execution.

    You can take all those If statements and implement them in VBA or distribute some of that logic among multiple cells so that no cell will contain more than 911 characters. I would choose the former solution because the logic will be easier to understand, debug, and extend to other parts of your project.
    Hello Joe,

    Thanks for your comments. Could you please elaborate a bit more on "implement them in VBA"
    BTW =Len(column) suggests I have 434 characters only

    Thanks/VKS

  4. #4
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Unable to incorporate a recorded code in a bigger code

    Interesting... the 911 limit may be associated with excel versions later than 2007.

    I would expect that you would be interested in a solution that does not require a cell with a formula 434 characters long. That could be implemented in VBA much more clearly.

    For example, looking at a very small subset of your logic, I see: IF(AND(OR(LEFT(RC[-31],3)... that seems to go on forever. I'll simplify that a little bit and close up that logic as simply as possible by replacing "RC[-31] by a cell value in order to illustrate my point.

    Let's say you had: = IF(AND(OR(LEFT(A1,3)= "MAR", A1 = "MARCH"),OR(LEFT(A2,3) = "FEB", A2 = "FEBRUARY"),"Cell A1 is MARCH/MAR & Cell A2 is FEBRUARY/FEB","") typed in Cell A3, it would either display: "Cell A1 is MARCH/MAR & Cell A2 is FEBRUARY/FEB" or nothing... but that is difficult to understand from looking at that monster formula.
    Alternatively, if you wrote a VBA implementation that does the same thing:
    Please Login or Register  to view this content.
    ...it is much easier to debug. So if there is an error, I could step through the code line by line, and use debugging tools to do things like return the value of A2 while the code is running to see what it is and why you're not getting the expected result.

    Recording a macro can be an easy way to get started coding but for reasons you're experiencing, it can lead to lots of issues if you don't know what the code does. And no one wants to debug a cell that is "only" 434 characters long because you get lost in parenthesis and embedded if/and/or... statements.

    So. If you describe what you want to do or record a series of more simple macros or upload a worksheet for the forum to debug/look at which includes your raw data on one worksheet and desired results on another worksheet, you may be able to move forward on your project more easily.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Dual code help. Unable to come up with a code to perform functions
    By justigger in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-12-2015, 06:06 AM
  2. Incorporate Loop Function In Recorded Macro
    By tarktran in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-07-2015, 05:57 AM
  3. Unable to edit macro recording code to be a relative code.
    By holaitsme in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-02-2014, 10:51 AM
  4. Replace Macro recorded code with more effective code
    By scaffdog845 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-12-2014, 01:09 AM
  5. Replies: 2
    Last Post: 12-17-2013, 11:51 AM
  6. incorporate string variable into VB code
    By itsthebike in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-22-2005, 02:05 PM
  7. incorporate variable into VB code
    By itsthebike in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2005, 10:32 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1