+ Reply to Thread
Results 1 to 11 of 11

Imported VBA code not working....

  1. #1
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Question Imported VBA code not working....

    Hello all...

    Last year, member rylo, helped me with some VBA code for one of my projects. If you are reading this post, rylo, you might recall the VBA code that you helped me with...and maybe you can help me once more. Otherwise, maybe some other members can help me.

    The VBA code below was provided by rylo last year. The code was designed to cycle through a list of teams...and FILL the background of each cell in the list with color...depending on which named range a match was found in.

    Please Login or Register  to view this content.
    This year I put together a slightly different spreadsheet and made the following changes to the VBA to conform to my new spreadsheet:

    Please Login or Register  to view this content.
    When I run the code, I get a Runtime error -' 1004': Method 'range' of object '_global' failed. (This error occurs on the VBA code line that is enlarged in the second version of the code, above. I tried to change the font color...but my color palette wouldn't open).

    Three questions....

    1. What part of the code did I change incorrectly? ...Or... Did I overlook any needed change(s)?

    2. How can I format the font color along with the background color using this VBA?

    3. The range $E$5:$AR$36 on sheet "MasterCopy" has been given a name.
    Can't I replace the RANGE ($E$5:$AR$36) with the RANGE NAME ("Selections_MasterCopy")?

    Thank you for any help you can provide....

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    The original code has two columns (E54:F112), the new version only one (F8:F73), might that be an issue?
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Talking

    The original code has two columns (E54:F112), the new version only one (F8:F73), might that be an issue?
    The referenced columns contain dates.

    In the older version, the dates appeared in merged cells.
    The dates in the new version occupy individual cells.

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Husker

    Vaguely remember this. Can you attach an example workbook of your current structure with the new code.

    rylo

  5. #5
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167
    Can you attach an example workbook of your current structure with the new code.
    You bet I can.....!!!

    But...don't have the time at the moment. (dammit...!!!)

    Will get it to you as soon as I can. (Might be tomorrow....don't give up on me....)

  6. #6
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167
    Here is the truncated spreadsheet:
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Took me a while!!!

    Change the line
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    You will also have to get rid of the days in sheet2!G19:G27 and make them teams.

    When you have done that, if you can't get it to work, then put up the revised workbook and I'll have another look.

    rylo

  8. #8
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167
    Thanks, rylo....

    I made the changes to the VBA code as suggested.

    As far as the DAYS were concerned, I simply eliminated them, as I don't
    really need them. Then I moved all of the teams one column to the left.

    When I press the RANDOMIZE button on Sheet2...I get a Run-time error.

    Run-time error '1004':
    Unable to set the ColorIndex property of the Font Class


    This error occurs AFTER your code changes...near the end of the subroutine;

    Please Login or Register  to view this content.
    Also, is there a simple way to add code to set the FONT for each CASE above??

    I've attached the updated sample for your inspection.
    Thanks, so much, for your help...
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Instead of actioning a range that has teams, you are going from column 5 to column 43 and this range included blank columns (21-23). It is having trouble establishing a value for colorind in the case statement.

    Perhaps enhance the case statement to have a default colorind of say xlnone. See how that goes.


    rylo

  10. #10
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167
    I'm going to try that......

    Or....Maybe is should just execute the procedure TWICE....once for each half of the range...........????????

  11. #11
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    That would probably be more certain.

    rylo

+ 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. code to stop working being shown
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-15-2008, 01:32 PM
  2. Run code but carry on working
    By stoney1977 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2008, 12:58 AM
  3. code not working
    By SRussell in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-16-2008, 08:11 AM
  4. Replies: 7
    Last Post: 03-03-2008, 11:48 AM
  5. Unlinking Imported Data
    By Donquick in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-15-2007, 09:29 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