+ Reply to Thread
Results 1 to 9 of 9

Generate messageBoxes over a range rather than individual cells to reduce code

  1. #1
    Registered User
    Join Date
    07-10-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2010
    Posts
    11

    Generate messageBoxes over a range rather than individual cells to reduce code

    Hi,
    I have a workbook containing a sheet for each letter of the alphabet. Each row relates to an item distributed. I have the distribution date in column A. In column B I have the 'Today' function. Column C is days lapsed using e.g. C2=B2-A2, formatted to a single number. I have a 27th page called 'Alarm, in which all the data from Column C of all pages is fed. Each cell is coded using the code
    Please Login or Register  to view this content.
    And so on, from A2 to A200 all the way to Z2 to Z200. Thus by selecting the alarm page, I can see which items have gone over 7 days.

    The trouble is;
    a) This is a massive load of spaghetti code
    b) It is too much data for the 64k limit for the VB editor in Excel 2003.
    In the worse case scenario, I do want all those message boxes, as once the time has lapsed, I would chase it up and change the date sent to the date chased (thanks for the prompt, TMShucks).
    If anyone can give me any pointers as to how to chop this code down to size, I would be really grateful.
    Many thanks,
    Mattbro
    Last edited by mattbro; 01-21-2012 at 12:41 PM. Reason: Violating thread rules

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,501

    Re: Generate messageBoxes over a range rather than individual cells to reduce code

    You'd loop through all the cells in the range At to Z200 ... but do you want all those message boxes (in the worst case)?


    However ...

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Generate messageBoxes over a range rather than individual cells to reduce code

    Conditional Formatting would make more sense
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,501

    Re: Generate messageBoxes over a range rather than individual cells to reduce code

    I agree with Roy on th CF.

    However, if this is what you want, try:

    Please Login or Register  to view this content.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    07-10-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Generate messageBoxes over a range rather than individual cells to reduce code

    Thanks guys-I looked at conditional formatting, and it is great, but the looping code seems to work better. I had to change the code slightly omitting the 'END IF' to;


    Please Login or Register  to view this content.
    Job done. Many thanks

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Generate messageBoxes over a range rather than individual cells to reduce code

    I'm not sure haow the code can be better. Conditional Formatting will be faster, less annoying - message boxes need to be clicked and the code won't work if macros are not enabled

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,501

    Re: Generate messageBoxes over a range rather than individual cells to reduce code

    Can't argue with Roy's logic.

    You didn't have to change the code, you chose to change it ... it worked as delivered. But no worries, you have to maintain it.

    Regards, TMS

  8. #8
    Registered User
    Join Date
    07-10-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Generate messageBoxes over a range rather than individual cells to reduce code

    Well RoyUK, I guess you would have to see it in-situ. The truth is, I really needed to see the code for other applications where I am performing similar roles-with copious quantities of spaghetti code, and I imagine this will take another dimension when I get asked to start adding further conditions;
    At the moment, there is one category of turnaround time-seven days. Both methods work fine for this. Shortly, I expect I will get asked to have alarms for different categories-items to alarm at 7days, different items to alarm at 8 days, 9 days and 10 days all based on the date sent (I know it's going to arrive on my desk...I can just see it coming). Conditional formatting looks better for this except I need all pages to feed into the 'alarm' page so that though all staff can enter the data, only one page needs to be looked at for all the alarms. I can't see how I can use conditional formatting in the extended scenario, but I may be able to modify the code to facilitate an extra parameter....or force the staff to code by category rather than by A-Z. If you have any ideas, I would be delighted to hear them.
    M

  9. #9
    Registered User
    Join Date
    07-10-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Generate messageBoxes over a range rather than individual cells to reduce code

    Hi TM Shucks. I was getting an error message on the final 'END IF'. By changing the code, the error message disappeared and all was fine....

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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