Detecting a cell value change

%3CLINGO-SUB%20id%3D%22lingo-sub-2621477%22%20slang%3D%22en-US%22%3EDetecting%20a%20cell%20value%20change%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2621477%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%20all.%20I%20have%20a%20simplified%20section%20of%20a%20complex%20(%3F!)%20spreadsheet%20I'm%20struggling%20with.%3C%2FP%3E%3CP%3EEntering%20a%20destination%20and%20journey%20finish%20mileometer%20reading%20fills%20a%20cell%20with%20the%20mileage.%3C%2FP%3E%3CP%3EFor%20payment%2C%20this%20mileage%20is%20segregated%20into%20bands%2C%20eg%201%20to%20100%20miles%2C%20Band%201%2C%20101%20to%20200%20miles%2C%20Band%202.%3C%2FP%3E%3CP%3EFor%20one%20worksheet%2C%20this%20should%20be%20relatively%20easy%2C%20even%20for%20me!%20But%20I%20just%20can't%20get%20it%20to%20work.%3C%2FP%3E%3CP%3EWhen%20the%20%22mileage%22%20cell%20value%20changes%2C%20it%20should%20call%20a%20sub%20which%20fills%20in%20the%20%22banding%22%20cell%20relative%20to%20the%20mileage%20value.%3C%2FP%3E%3CP%3EBut%2C%20and%20this%20is%20the%20first%20problem%2C%20entering%20the%20finish%20mileage%2C%20which%20allows%20the%20%22mileage%22%20cell%20to%20display%2C%20triggers%20the%20change%20mechanism%2C%20steering%20the%20Target_Address%20away%20from%20the%20intended%20target%20(%22mileage%22)%20to%20itself%2C%20%22Finish%20Miles%22.%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20second%20problem%20may%20be%20solved%20if%20the%20first%20one%20is%2C%20perhaps.%20How%20to%20have%20the%20sub%20sitting%20in%20the%20module%2C%20being%20called%20by%20the%20Active%20Sheet%2C%20instead%20of%20sitting%20in%20each%20sheet.%20There%20are%20many%20more%20sheets%20than%20in%20the%20excerpt.%3C%2FP%3E%3CP%3EAny%20and%20all%20help%20%2F%20advice%20will%20be%20appreciated.%3C%2FP%3E%3CP%3EBest%20regards%2C%20Pete%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2621477%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2621567%22%20slang%3D%22en-US%22%3ERe%3A%20Detecting%20a%20cell%20value%20change%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2621567%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F378502%22%20target%3D%22_blank%22%3E%40Peter_Field%3C%2FA%3E%26nbsp%3BDon't%20think%20you%20need%20VBA%20here.%20You%20can%20use%20a%20lookup%20table%20like%20in%20the%20attached%20workbook.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2621598%22%20slang%3D%22en-US%22%3ERe%3A%20Detecting%20a%20cell%20value%20change%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2621598%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F378502%22%20target%3D%22_blank%22%3E%40Peter_Field%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDo%20you%20really%20need%20code%3F%20You%20could%20enter%20the%20following%20formula%20in%20E2%2C%20then%20fill%20down%20as%20far%20as%20you%20want%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3DIF(D2%3D%22%22%2C%22%22%2C%22Band%20%22%26amp%3BROUNDUP(D2%2C-2)%2F100)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi, all. I have a simplified section of a complex (?!) spreadsheet I'm struggling with.

Entering a destination and journey finish mileometer reading fills a cell with the mileage.

For payment, this mileage is segregated into bands, eg 1 to 100 miles, Band 1, 101 to 200 miles, Band 2.

For one worksheet, this should be relatively easy, even for me! But I just can't get it to work.

When the "mileage" cell value changes, it should call a sub which fills in the "banding" cell relative to the mileage value.

But, and this is the first problem, entering the finish mileage, which allows the "mileage" cell to display, triggers the change mechanism, steering the Target_Address away from the intended target ("mileage") to itself, "Finish Miles". 

The second problem may be solved if the first one is, perhaps. How to have the sub sitting in the module, being called by the Active Sheet, instead of sitting in each sheet. There are many more sheets than in the excerpt.

Any and all help / advice will be appreciated.

Best regards, Pete

4 Replies

@Peter_Field Don't think you need VBA here. You can use a lookup table like in the attached workbook.

 

@Peter_Field 

Do you really need code? You could enter the following formula in E2, then fill down as far as you want:

=IF(D2="","","Band "&ROUNDUP(D2,-2)/100)
Thank you, Hans. I will try this.
I haven't come across "Roundup" before, so will search to learn more.
Best regards, Pete
Hi, friend
Thank you so much for your response. It took me totally by surprise, as I never considered using Lookup in this aspect.
Many thanks, again, for this neat solution.
Best regards, Pete