SOLVED
Home

Formula or function for IF statement based on cell color

%3CLINGO-SUB%20id%3D%22lingo-sub-78267%22%20slang%3D%22en-US%22%3EFormula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78267%22%20slang%3D%22en-US%22%3E%3CP%3EI%20don't%20know%20how%20to%20code%20in%20VBA%20but%20am%20trying%20to%20automate%20an%20if%2Fthen%20calculation%20based%20on%20cell%20color.%20As%20shown%20in%20the%20picture%2C%20if%20the%20colors%20of%20the%20cells%20in%20column%20B%20are%20the%20same%20as%20those%20in%20Column%20G%20across%20the%20row%2C%20I%20want%20to%20subtract%20the%20values%20in%20columns%20F%20and%20K%20in%20the%20same%20row%20to%20return%20the%20absolute%20value%20of%20the%20subtraction%20in%20column%20L.%20If%20the%20colors%20of%20the%20cells%20are%20different%2C%20I%20want%20to%20add%20the%20values%20in%20columns%20F%20and%20K%20and%20return%20the%20value%20in%20column%20L.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F15931iDC88DD576E80365E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22excel.JPG%22%20title%3D%22excel.JPG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EI%20will%20have%20multiple%20tables%20of%20varying%20numbers%20of%20rows%20where%20I%20need%20to%20perform%20this%20operation.%20Any%20help%20is%20greatly%20appreciated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-78267%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20%26amp%3B%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ENeed%20Help%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-320776%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-320776%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%20I%20got%20this%20solution%20to%20work%20for%20when%20I%20manually%20apply%20a%20color%20to%20a%20cell%2C%20but%20it%20is%20not%20working%20for%20cells%20that%20are%20highlighted%20because%20of%20the%20Conditional%20Formatting%20I%20apply%20on%20duplicate%20rows.%3C%2FP%3E%3CP%3EI%20want%20to%20easily%20filter%20duplicate%20rows%20but%20filtering%20on%20color%20is%20not%20working%20for%20more%20than%20a%20couple%20hundred%20rows....%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-320706%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-320706%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Kelvin%3C%2FP%3E%3CP%3EPlease%20help%2Ci%20want%20to%20colour%20code%20the%20cell%20with%20green%20using%20if%20formular%20for%20a%20value%20ranging%2050%20to%200.That%20is%20checking%20with%20a%20certain%20cell%20that%20contains%20e.g%20numder%20of%20days%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-320705%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-320705%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Kelvin%3C%2FP%3E%3CP%3EPlease%20help%2Ci%20want%20to%20colour%20code%20the%20cell%20with%20green%20using%20if%20formular%20for%20a%20value%20ranging%2050%20to%200.That%20is%20checking%20with%20a%20certain%20cell%20that%20contains%20e.g%20numder%20of%20days%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-237901%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-237901%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Sergei%2C%20worked%20a%20treat%20-%20thanks%20so%20much.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-236829%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-236829%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20David%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20could%20be%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3DIF(C2%26gt%3B0%2C%20%22Active%22%2CIF(B2%26gt%3B0%2C%20%22Dormant%22%2C%20%22Inactive%22))%3C%2FPRE%3E%0A%3CP%3Eand%20attached%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-234967%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-234967%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Sergei%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20replying.%20I%20hope%20the%20below%20makes%20a%20little%20more%20sense.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBelow%20is%20the%20criteria%20I%20was%20given%20and%20below%20I%20have%20attached%20a%20screen%20shot%20of%20the%20spreadsheet%20with%20the%20relevant%20columns%20that%20my%20query%20relates%20to.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EMake%20the%20%E2%80%98Status%E2%80%99%20column%20field%20automatically%20show%20the%20words%20Active%2C%20Dormant%20or%20Inactive%20based%20on%20the%20following%20conditions%3A%3C%2FLI%3E%3CUL%3E%3CLI%3EActive-%20if%20there%20were%20purchases%20in%20the%20current%2012%20months%20(third%20column)%3C%2FLI%3E%3CLI%3EDormant-%20if%20there%20was%20purchases%20in%20previous%2012%20month%20period%20(Second%20Column)%20but%20nothing%20in%20Current%2012%20months%20period%20(third%20column)%3C%2FLI%3E%3CLI%3EInactive-%20if%20there%20was%20no%20purchases%20in%20second%20or%20third%20column%3C%2FLI%3E%3C%2FUL%3E%3C%2FUL%3E%3CP%3ENote%3A%20I'm%20thinking%20the%20answer%20is%20utilising%20a%20IFS%20%26amp%3B%20ISBLANK%20combined%20formula%2C%20but%20so%20far%20I%20haven't%20been%20able%20to%20get%20this%20combination%20to%20work%20to%20encompass%20all%20three%20criteria..if%20that%20makes%20sense.%20So%20far%20I%20have%20only%20been%20able%20to%20get%20the%20following%20IF%20formula%20to%20work%20but%20it%20is%20not%20the%20total%20solution%3A%20%3DIF(W5%3D0%2C(%22Inactive%22)%2C(%22Active%22))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20422px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F43488iE2E5DC9274EA46EA%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Capture1.JPG%22%20title%3D%22Capture1.JPG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-234803%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-234803%22%20slang%3D%22en-US%22%3E%3CP%3EDavid%2C%20it%20depends%20on%20which%20conditional%20formatting%20rules%20you%20use.%20If%20you%20provide%20small%20sample%20it'll%20be%20easier%20to%20answer.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-234518%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-234518%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Sergei%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20sort%20of%20figured%20that%20but%20I%20can%20seem%20to%20find%20a%20formula%20to%20achieve%20the%20outcome.%20Do%20you%20have%20a%20example%20formula%20that%20might%20work%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%20David%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-234205%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-234205%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20David%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20use%20conditional%20formatting%20you%20may%20apply%20same%20formulas%20as%20for%20conditional%20formatting%20rules%20to%20your%20another%20column%20to%20return%20the%20text.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-234177%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-234177%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20having%20a%20similar%20problem%2C%20let's%20say%20on%20my%20spreadsheet%20in%20column%20W%20on%20a%20range%20of%20W5%3AW268%20has%20values%20showing%20as%20different%20colours%20based%20on%20conditional%20formatting%20formulas.%20Now%20what%20I%20want%20to%20do%20in%20another%20column%20is%20based%20on%20the%20colour%20in%20the%20range%20W5%3AW268%20I%20want%20a%20word%20to%20appear.%20So%20if%20the%20colour%20is%20green%2C%20I%20want%20the%20text%20in%20the%20adjacent%20column%20to%20say%20Active%2C%20if%20the%20colour%20is%20red%2C%20Inactive%20%26amp%3B%20if%20the%20colour%20orange%2C%20Domant.%20I%20can't%20find%20anywhere%20online%20showing%20me%20how%20to%20achieve%20this.%20Thanks%20heaps%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78494%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78494%22%20slang%3D%22en-US%22%3E%3CP%3EKevin%2C%20this%20worked%20like%20a%20charm.%20You%20are%20the%20hero%20of%20the%20day!!%20Thanks%20ever%20so%20much!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78322%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78322%22%20slang%3D%22en-US%22%3E%3CP%3EYou'll%20have%20to%20save%20your%20file%20as%20%22.xlsm%22%20(m%20for%20macro).%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78321%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78321%22%20slang%3D%22en-US%22%3E%3CP%3EStep%201%20Paste%20code%20(found%20at%20bottom)%26nbsp%3Binto%20a%20new%20module.%20ALT%20F11%20shortcut%20should%20open%20the%26nbsp%3Bcode%20area.%3CBR%20%2F%3EStep%202%20In%20cell%20O1%20paste%20formula%3A%20%3CSTRONG%3E%3DInteriorColor(B1)%3C%2FSTRONG%3E%20drag%20formula%20down%3CBR%20%2F%3EStep%203%20In%20cell%20P1%20paste%20formula%3A%20%3CSTRONG%3E%3DInteriorColor(G1)%3C%2FSTRONG%3E%20drag%20formula%20down%3CBR%20%2F%3EStep%204%20In%20cell%20L1%20paste%20formula%3A%20%3CSTRONG%3E%3DIF(O1%26lt%3B%26gt%3BP1%2CF1%2BK1%2CABS(F1-K1))%3C%2FSTRONG%3E%20drag%20formula%20down%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20this%20work%20for%20you%20Laurie%3F%3C%2FP%3E%3CP%3ECheers%2C%3C%2FP%3E%3CP%3EKevin%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFunction%20InteriorColor(CellColor%20As%20Range)%3CBR%20%2F%3EApplication.Volatile%3CBR%20%2F%3EInteriorColor%20%3D%20CellColor.Interior.ColorIndex%3CBR%20%2F%3EEnd%20Function%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F15951i557270935BBFCF8D%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22if%20colors%20different%20then%20add%20else%20calc%20abs%20difference.JPG%22%20title%3D%22if%20colors%20different%20then%20add%20else%20calc%20abs%20difference.JPG%22%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F15952i12587484CEAF5622%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22Step%201.JPG%22%20title%3D%22Step%201.JPG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-530744%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-530744%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EI%20have%20created%20a%20spreadsheet%20that%20has%20multiple%20cells%20that%20go%20red%20based%20on%20conditional%20formatting.%20I%20have%20another%20sheet%20that%20has%20hyperlink%20cells%20to%20the%20other%20sheets%2C%20can%20I%20get%20these%20hyperlink%20cells%20to%20go%20red%20if%20any%20of%20the%20cells%20on%20the%20hyperlinked%20sheet%20is%20red%26nbsp%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CI%3EPrivate%20Sub%20Worksheet_SelectionChange(ByVal%20Target%20As%20Range)%3CBR%20%2F%3EMe.Range(%22B4%22).Interior.Color%20%3D%20Me.Range(%22A1%22).DisplayFormat.Interior.Color%3CBR%20%2F%3EEnd%20Sub%3C%2FI%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3Ethis%20works%20on%20the%20same%20sheet%20but%20as%20soon%20as%20you%20introduce%20multiple%20cells%20it%20turns%20black%26nbsp%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CI%3EPrivate%20Sub%20Worksheet_SelectionChange(ByVal%20Target%20As%20Range)%3CBR%20%2F%3EMe.Range(%22B4%22).Interior.Color%20%3D%20Me.Range(%22A1%3AB1%3AC1%22).DisplayFormat.Interior.Color%3CBR%20%2F%3EEnd%20Sub%3C%2FI%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3Eor%20cells%20from%20another%20sheet%20it%20fails%20error%20code%201004%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CI%3EPrivate%20Sub%20Worksheet_SelectionChange(ByVal%20Target%20As%20Range)%3CBR%20%2F%3EMe.Range(%22B4%22).Interior.Color%20%3D%20Me.Range(%22Greenbrook!%24C%243%22).DisplayFormat.Interior.Color%3CBR%20%2F%3EEnd%20Sub%3C%2FI%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EI%20tried%20this%20across%20sheet%2C%20this%20is%20for%20a%20single%20cell%2C%20I'm%20hoping%20to%20be%20able%20to%20look%20at%20all%20cells%20on%20the%20said%20sheet%20and%20show%20red%20if%20any%20cell%20on%20the%20other%20sheet%20are%20red%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-794148%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-794148%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F20200%22%20target%3D%22_blank%22%3E%40Kevin%20Lehrbass%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMabye%20you%20can%20help%20me%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20value%20in%20cell%20J18%20that%20i%20would%20like%20to%20return%20to%20cell%20C23%20-%20IF%20-%20cell%20C19%20has%20the%20color%20red%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20that%20possible%3F%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-796185%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20or%20function%20for%20IF%20statement%20based%20on%20cell%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-796185%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F20200%22%20target%3D%22_blank%22%3E%40Kevin%20Lehrbass%3C%2FA%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F62598%22%20target%3D%22_blank%22%3E%40Laurie%20McDowell%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20implemented%20this%20for%20a%20similar%20problem%20and%20it%20worked%20well!%20However%2C%20if%20I%20change%20the%20color%20of%20my%20cell%2C%20the%20output%20value%20will%20not%20update%20unless%20I%20go%20into%20the%20formal%20and%20hit%20enter.%20Is%20there%20a%20way%20this%20will%20refresh%20automatically%3F%20I%20even%20tried%20the%20refresh%20function%20for%20the%20entire%20workbook%2C%20but%20that%20didn't%20work%20either.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Laurie McDowell
New Contributor

I don't know how to code in VBA but am trying to automate an if/then calculation based on cell color. As shown in the picture, if the colors of the cells in column B are the same as those in Column G across the row, I want to subtract the values in columns F and K in the same row to return the absolute value of the subtraction in column L. If the colors of the cells are different, I want to add the values in columns F and K and return the value in column L.

 

excel.JPG

I will have multiple tables of varying numbers of rows where I need to perform this operation. Any help is greatly appreciated.

 

 

 

 

 

16 Replies
Solution

Step 1 Paste code (found at bottom) into a new module. ALT F11 shortcut should open the code area.
Step 2 In cell O1 paste formula: =InteriorColor(B1) drag formula down
Step 3 In cell P1 paste formula: =InteriorColor(G1) drag formula down
Step 4 In cell L1 paste formula: =IF(O1<>P1,F1+K1,ABS(F1-K1)) drag formula down

 

Does this work for you Laurie?

Cheers,

Kevin

 

Function InteriorColor(CellColor As Range)
Application.Volatile
InteriorColor = CellColor.Interior.ColorIndex
End Function 

if colors different then add else calc abs difference.JPGStep 1.JPG

 

You'll have to save your file as ".xlsm" (m for macro).

Kevin, this worked like a charm. You are the hero of the day!! Thanks ever so much!

I'm having a similar problem, let's say on my spreadsheet in column W on a range of W5:W268 has values showing as different colours based on conditional formatting formulas. Now what I want to do in another column is based on the colour in the range W5:W268 I want a word to appear. So if the colour is green, I want the text in the adjacent column to say Active, if the colour is red, Inactive & if the colour orange, Domant. I can't find anywhere online showing me how to achieve this. Thanks heaps

Hi David,

 

If you use conditional formatting you may apply same formulas as for conditional formatting rules to your another column to return the text.

Hi Sergei,

 

I sort of figured that but I can seem to find a formula to achieve the outcome. Do you have a example formula that might work?

 

Thanks, David

David, it depends on which conditional formatting rules you use. If you provide small sample it'll be easier to answer.

 

Hi Sergei,

 

Thank you for replying. I hope the below makes a little more sense.

 

Below is the criteria I was given and below I have attached a screen shot of the spreadsheet with the relevant columns that my query relates to.

 

  • Make the ‘Status’ column field automatically show the words Active, Dormant or Inactive based on the following conditions:
    • Active- if there were purchases in the current 12 months (third column)
    • Dormant- if there was purchases in previous 12 month period (Second Column) but nothing in Current 12 months period (third column)
    • Inactive- if there was no purchases in second or third column

Note: I'm thinking the answer is utilising a IFS & ISBLANK combined formula, but so far I haven't been able to get this combination to work to encompass all three criteria..if that makes sense. So far I have only been able to get the following IF formula to work but it is not the total solution: =IF(W5=0,("Inactive"),("Active"))

 

Capture1.JPG

Hi David,

 

That could be 

=IF(C2>0, "Active",IF(B2>0, "Dormant", "Inactive"))

and attached

Hi Sergei, worked a treat - thanks so much.

Hi Kelvin

Please help,i want to colour code the cell with green using if formular for a value ranging 50 to 0.That is checking with a certain cell that contains e.g numder of days 

 

Hi Kelvin

Please help,i want to colour code the cell with green using if formular for a value ranging 50 to 0.That is checking with a certain cell that contains e.g numder of days 

 

Hi, I got this solution to work for when I manually apply a color to a cell, but it is not working for cells that are highlighted because of the Conditional Formatting I apply on duplicate rows.

I want to easily filter duplicate rows but filtering on color is not working for more than a couple hundred rows....

 

Thanks!

I have created a spreadsheet that has multiple cells that go red based on conditional formatting. I have another sheet that has hyperlink cells to the other sheets, can I get these hyperlink cells to go red if any of the cells on the hyperlinked sheet is red 

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("B4").Interior.Color = Me.Range("A1").DisplayFormat.Interior.Color
End Sub


this works on the same sheet but as soon as you introduce multiple cells it turns black 

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("B4").Interior.Color = Me.Range("A1:B1:C1").DisplayFormat.Interior.Color
End Sub


or cells from another sheet it fails error code 1004

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("B4").Interior.Color = Me.Range("Greenbrook!$C$3").DisplayFormat.Interior.Color
End Sub


I tried this across sheet, this is for a single cell, I'm hoping to be able to look at all cells on the said sheet and show red if any cell on the other sheet are red

@Kevin Lehrbass 

 

Mabye you can help me

 

I have a value in cell J18 that i would like to return to cell C23 - IF - cell C19 has the color red

 

Is that possible?

 

 

@Kevin Lehrbass @Laurie McDowell 

 

I implemented this for a similar problem and it worked well! However, if I change the color of my cell, the output value will not update unless I go into the formal and hit enter. Is there a way this will refresh automatically? I even tried the refresh function for the entire workbook, but that didn't work either.