+ Reply to Thread
Results 1 to 15 of 15

Force Change Event in workbook

  1. #1
    Registered User
    Join Date
    10-10-2008
    Location
    UK
    Posts
    15

    Force Change Event in workbook

    Please can anyone help with the following;

    I Have a workbook with various named worksheets which I use to calculate perfomance based on Total No. of items handled divided by total labour hours used giving me a value for Items per Labour Hour. Depending on this value some cells are formatted in a colour in order to draw the users attention to it. I also have a summary sheet where some of the info from each worksheet is displayed. On the summary sheet there is a target value for items per labour hour. The individual worksheets code works fine but I cannot get the worksheet cells to reformat if I ammend the target value on the summary.

    I have used the following code on the ThisWorkbook Change event
    Please Login or Register  to view this content.
    and also
    Created a module with the following code
    Please Login or Register  to view this content.
    Cheers
    Colin
    Last edited by romperstomper; 03-22-2011 at 07:56 AM. Reason: code tags

  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,986

    Re: Force Change Event in workbook

    Why don't you just use Conditional Formatting on the source sheets?

    It might help others to help you if you uploaded a sample workbook with some typical data rather than just post the code out of context.

    Regards
    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
    Registered User
    Join Date
    10-10-2008
    Location
    UK
    Posts
    15

    Re: Force Change Event in workbook

    Hi TMShucks

    I have uploaded the file in the hope someone can solve my problem. The worksheet I am currently working on is called "CHINA"

    As a test, If you look at the summary sheet I,6 this is what is meant to be the target value. This then is tested in my VBA code against the worksheet "CHINA" P,30 value and if the P,30 value >= summary sheet I,6 then display a colour (bright green for now) otherwise highlight in red so as to draw attention to the fact the target hasn't been met.

    My worksheets worked fine unless I ammended the target value on teh summary sheet as this then was not reflected in the individual worksheet "CHINA" in this case.

    Colin
    Attached Files Attached Files

  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,986

    Re: Force Change Event in workbook

    This is probably a stupid question but if you change the target value for one row, for example, CHINA, why do you then loop through all the sheets?

    Whatever, I think it is this bit of code that is wrong:

    Please Login or Register  to view this content.
    as in:

    Please Login or Register  to view this content.

    You say that the comparison is (should be) against cell I6 ... I think you need to count through the alphabet and think again ;-)


    Regards

  5. #5
    Registered User
    Join Date
    10-10-2008
    Location
    UK
    Posts
    15

    Re: Force Change Event in workbook

    row 6 in this case was only relating to 1 of the sheets and by looping through all the sheets after ammending anything in column 10 I am checking for any ammendments. ie.

    Summarysheet row 3 column 10 = Worksheet.HEARTS value
    Summarysheet row 4 column 10 = Worksheet.Celery value
    Summarysheet row 5 column 10 = Worksheet.Sticks value
    Summarysheet row 6 column 10 = Worksheet.CHINESE value
    Summarysheet row 7 column 10 = Worksheet.COS value
    etc . etc

    Counting from A to to Z was never my strong point

  6. #6
    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,986

    Re: Force Change Event in workbook

    Your target values on the Summary sheet are in column I, which is column 9, not column 10. Hence the reference to that line of code in my previous post.

    Regards

  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,986

    Re: Force Change Event in workbook

    Because you have a Sheet Change event in the Workbook module, *any* change on *any* sheet will fire the Change event. So, if you make a Change on the CHINA sheet, you'd do whatever you need to relating to that sheet. If, however, you make a Change on the Summary sheet, I would have thought you only needed to process the sheet that the change related to.

    I may be very wrong as I don't follow your logic but it looks to me as though you are processing all 10 sheets every time you make any change on the Summary sheet.

    I still don't know why you don't use CF as then you wouldn't need any code.

    Regards

  8. #8
    Registered User
    Join Date
    10-10-2008
    Location
    UK
    Posts
    15

    Re: Force Change Event in workbook

    Hi TMShucks

    Firstly thanks for taking the time to look at this problem.

    I had inadvertantly uploaded a workbook that I had ammended the sumary sheet on hence the error in my alphabetical calculations.

    I have a problem with using CF as when I try to use say the "CHINA" worksheet and try to compare the value to the target value on the Summary sheet I get an error message "You may not use references to other worksheets for conditional formatting"

    Regards

    Colin

  9. #9
    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,986

    Re: Force Change Event in workbook

    First question then: is the problem fixed?

    With regard to using CF across sheets, all you need to do is assign a named range to each of the target values, for example, "ChinaT" without the quotes. You will then be able to use the named range (cell) in any formula you use in the CF.

    Regards

  10. #10
    Registered User
    Join Date
    10-10-2008
    Location
    UK
    Posts
    15

    Re: Force Change Event in workbook

    Hi TMShucks

    I have uploaded my workbook so If you get chance to take a look at the "CHINA" worksheet and alter the value on C22 to 1 or more you will see the formatting that occurs (garish as it is, for testing only). I have yet to ammend the code to look at the various rows relating to the corresponding worksheets. But, my main problem at the moment is that whilst I can get the formatting to work if I alter the values on teh individual worksheets I cannot figure out how to get the same to happen if the user changes the summary sheet target values in column J (row 6 in this instance).

    Regards

    Colin
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    10-10-2008
    Location
    UK
    Posts
    15

    Re: Force Change Event in workbook

    Looks like I've actually cured my initial problem now by adding in the following code into my Workbook_SheetChange event

    Case "Summary"
    For Each Sh In ThisWorkbook.Worksheets
    Select Case Sh.Name
    Case "ICE X 10", "CHINA", "COS", "ICEX12", "HEARTS", "gem", "CELERY", "STICKS" 'Excluded Summary sheet
    FormatSheet Sh
    End Select
    Next

    Thanks for everyones help.

  12. #12
    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,986

    Re: Force Change Event in workbook

    I'm pleased and not a little relieved that you have a successful outcome. ;-)

    I'm still a little bemused as to why you loop through all the sheets when you change *one* target on the summary sheet. If you named the worksheets to match the products listed on the summary sheet you could pass the product name (from the relevant cell) to the format sheet routine and only process the one sheet relating to the changed target. Or am I missing something?

    Regards

  13. #13
    Registered User
    Join Date
    10-10-2008
    Location
    UK
    Posts
    15

    Re: Force Change Event in workbook

    I am a novice at this programming lark and had used the "looping" through sheets on another persons advice. I am open to offers of improvement ;-]

    I am now also having trouble with the following code

    Worksheets("Summary").Cells(Counter, 6).Interior.Color = RGB(255, 255, 255)

    I get the Runtime error 1004 Unable to set the colour property of the Interior class

  14. #14
    Registered User
    Join Date
    10-10-2008
    Location
    UK
    Posts
    15

    Re: Force Change Event in workbook

    Just realised that my error must have been caused by me protecting the cells that I was formatting with my code

  15. #15
    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,986

    Re: Force Change Event in workbook

    I think that the attached workbook addresses the issue of looping through all the worksheets.

    It's not tested to destruction but it seems to work.

    You should now be able to change a target on the summary sheet and have it reflected on the form sheet and vice versa.

    Note that I have aligned all the field names on the summary sheet with the tab names. It won't work if they are not aligned in this way.

    Regards
    Attached Files Attached Files

+ 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