+ Reply to Thread
Results 1 to 6 of 6

Problem selecting a range in code

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Problem selecting a range in code

    The attached work book shows a table and the code I am using to format the table by putting in borders and colouring total rows yellow etc.
    This code worked fine while I was running the sub routines individually as I was building the application. When I wrote code so the whole lot could be fired off by a button I started to get errors at the line labelled 100 in the Horizontals sub routine. The error was that the select method of Range failed. When I deconstructed the button code the problem persisted.
    The Range, which is dynamic, is named in the Define Range tool, but I have not done that in the attachment.
    I have eliminated the obvious things such as typos or the range having no values and I am now at a loss as to how to proceed. Can any one help please
    John
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Problem selecting a range in code

    John

    There is no selecting in the Horizontals sub.

    You do however have this in the MakeBorders sub.
    Please Login or Register  to view this content.
    Is that the line causing the error?

    If it is and this is how the sub is called,
    Please Login or Register  to view this content.
    then the problem is that there is no named range called 'GUMTABLE'.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Problem selecting a range in code

    Norie, Thanks for your reply. I am sorry that I misled you a bit on the attachment I was writing from memory.
    Yes Range (Tablename).Select is causing the problem. It is used for 4 tables and each of the generates the same error so I had thought that it was unlikely to be caused by a faulty name. I will go away and check for unwanted spaces etc.
    John

  4. #4
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Problem selecting a range in code

    Norie, Thanks for your reply. I am sorry that I misled you a bit on the attachment I was writing from memory.
    Yes Range (Tablename).Select is causing the problem. It is used for 4 tables and each of the generates the same error so I had thought that it was unlikely to be caused by a faulty name. I will go away and check for unwanted spaces etc.
    John

  5. #5
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Problem selecting a range in code

    I am still in trouble trying to select a range to format in code. I start with the following sub
    Please Login or Register  to view this content.
    I am sure the range has values, and when stepping through the code I get expected values for x and y
    Yet I get the message "Select Method of Range class failed"
    I think that there must be a problem in the context in which this code is run because sometimes when I am firing the sub manually it will run.
    What should I be looking for?
    John

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Problem selecting a range in code

    How does this work, or not work?
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Problem selecting a range in code

    Norrie,
    With the small change of omitting .Name = "Table" ( and I didn't need the name except to run this code) your suggestion works fine. I have been held up by this problem for more than a week so I expect you can imagine my relief. More than one forum guru has said avoid "select" I will have to take notice now. Thanks very much for your help.
    By the bye I noticed your location. Stay with us we're better together!
    John

+ 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. [SOLVED] problem with selecting next row code
    By smaier69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-06-2012, 08:34 PM
  2. Selecting a named range in VBA code
    By barksmith in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-16-2008, 10:46 AM
  3. Selecting a Range in Code
    By scottintexas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-23-2008, 09:29 AM
  4. [SOLVED] problem selecting a range using variables
    By cass calculator in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-23-2006, 04:45 PM
  5. [SOLVED] Selecting range problem
    By dorre in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-25-2006, 10:40 PM

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