SOLVED
Home

Count number of blank cells till last non empty cell in a column.

%3CLINGO-SUB%20id%3D%22lingo-sub-172986%22%20slang%3D%22en-US%22%3ECount%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-172986%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20-%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20want%20to%20count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column%20but%20could%20not%20figure%20out%20how%20to%20do%20this%2C%20can%20you%20please%20help%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20I%20use%20%3CSTRONG%3ECountblank%3C%2FSTRONG%3E%20formula%2C%20it%20takes%20an%20argument%20as%20range%20which%20should%20be%20known%20in%20the%20beginning%20itself%20which%20is%20a%20problem%20because%20then%20it%20becomes%20manual%20work%20to%20mention%20the%20range%20everytime%20as%20my%20column%20data%20(number%20of%20rows)%20can%20change%20many%20times%2C%20and%20different%20columns%20can%26nbsp%3B%20have%20different%20number%20of%20rows.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIs%20there%20a%20way%20to%20mention%20end%20limit%20of%20the%20range%20as%20row%20number%20of%20last%20non%20empty%20cell%20in%20that%20column%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThank%20you%20in%20advance%2C%3C%2FP%3E%0A%3CP%3ESaurabh%20Khanna.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-172986%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20%26amp%3B%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ERequests%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-297185%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-297185%22%20slang%3D%22en-US%22%3EMany%20Thanks%20Sergei%20for%20your%20help%2C%20it%20works%20great.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-297184%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-297184%22%20slang%3D%22en-US%22%3EMany%20Thanks%20Jamil%20for%20your%20help%2C%20it%20works%20great.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-295738%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-295738%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20may%20change%20IFNA%20on%20IFERROR%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-295246%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-295246%22%20slang%3D%22en-US%22%3E%3CP%3Eit%20is%20because%20you%20are%20probably%20using%20Excel%202010%20which%20does%20not%20have%20IFNA%20function.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESO%20i%20replaced%20is%20with%20IF%20ISNA%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3Blike%20this%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eit%20is%20again%20with%20Control%20shift%20enter.%26nbsp%3B%20see%20attached%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DIF(ISNA(COUNTBLANK(A3%3AINDEX(A3%3AA1048576%2CMATCH(2%2C1%2F(A3%3AA1048576%26lt%3B%26gt%3B%22%22)))))%2C0%2CCOUNTBLANK(A3%3AINDEX(A3%3AA1048576%2CMATCH(2%2C1%2F(A3%3AA1048576%26lt%3B%26gt%3B%22%22)))))%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-295235%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-295235%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20I%20downloaded%20your%20file%2C%20I%20am%20not%20getting%20result%2C%20it%20shows%20error.%3C%2FP%3E%3CP%3EI%20have%20taken%20screenshot%20%22A%22%20when%20file%20is%20downloaded%20and%20opened%2C%20and%20%22B%22%20when%20I%20pasted%20the%20formula%20in%20the%20cell(by%20Ctrl%2BShift%2BEnter).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAm%20i%20doing%20something%20wrong%20at%20me%20end%2C%20or%20is%20it%20Excel%20version%20compatibility%20issue%3B%20I%20am%20using%20Excel%202010%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20You%2C%3C%2FP%3E%3CP%3ESaurabh%20Khanna.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-295232%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-295232%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHello%20-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20I%20downloaded%20your%20file%2C%20I%20am%20not%20getting%20result%2C%20it%20shows%20error.%3C%2FP%3E%3CP%3EI%20have%20taken%20screenshot%20%221%22%20when%20file%20is%20downloaded%20and%20opened%2C%20and%20%222%22%20when%20I%20pasted%20the%20formula%20in%20the%20cell.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAm%20i%20doing%20something%20wrong%20at%20me%20end%2C%20or%20is%20it%20Excel%20version%20compatibility%20issue%3B%20I%20am%20using%20Excel%202010%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20You%2C%3C%2FP%3E%3CP%3ESaurabh%20Khanna.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-295018%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-295018%22%20slang%3D%22en-US%22%3E%3CP%3EOr%3C%2FP%3E%0A%3CPRE%3E%3DIFNA(COUNTBLANK(A3%3AINDEX(A%3AA%2CLOOKUP(2%2C1%2F(A%3AA%26lt%3B%26gt%3B%22%22)%2CROW(A%3AA))))%2C0)%3C%2FPRE%3E%0A%3CP%3E(regular%20formula)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-294660%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-294660%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Saurabh%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ethis%20is%20the%20formula%20to%20put%20in%20A2%20and%20drag%20to%20the%20right%20.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20note%20that%20it%20is%20an%20array%20formula%2C%20so%20it%20must%20be%20entered%20with%20holding%20Control%2BShift%2BEnter.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DIFNA(COUNTBLANK(A3%3AINDEX(A3%3AA1048576%2CMATCH(2%2C1%2F(A3%3AA1048576%26lt%3B%26gt%3B%22%22))))%2C0)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Esee%20attached%20workbook%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-294467%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-294467%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHello%20-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20able%20to%20get%20the%20desired%20results%20and%20formula%20also%20works%20if%20i%20Past%20it%20for%20any%20column.%3C%2FP%3E%3CP%3EHowever%2C%20I%20noticed%20that%20if%20there%20is%20no%20data%20in%20a%20specified%20range%20for%20that%20column%2C%20then%20it%20does%20not%20work%20properly%2C%20can%20there%20be%20a%20way%20to%20treat%20this%20situation%20of%20no%20data%20as%20an%20exception%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAttaching%20the%20reference%20sheet%20with%20an%20example%20scenario.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20You%2C%3C%2FP%3E%3CP%3ESaurabh.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-190813%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-190813%22%20slang%3D%22en-US%22%3E%3CPRE%3E%3DCOUNTBLANK(A%244%3AINDEX(%24A4%3A%24A%24500000%2CSUMPRODUCT(MAX((%24A4%3A%24A%24500000%26lt%3B%26gt%3B%22%22)*(ROW(%24A4%3A%24A%24500000)-ROW(%24A%244)%2B1)))))%3C%2FPRE%3E%0A%3CP%3Eor%3C%2FP%3E%0A%3CPRE%3E%3DCOUNTBLANK(OFFSET(A%244%2C0%2C0%2CAGGREGATE(14%2C6%2C1%2F(%24A4%3A%24A%24500000%26lt%3B%26gt%3B%22%22)*(ROW(%24A4%3A%24A%24500000)-ROW(%24A%244)%2B1)%2C1)))%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-190811%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-190811%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHello%20Jamil%20-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYour%20suggestion%20worked%20for%20me%20to%20a%20great%20extent.%3C%2FP%3E%3CP%3EI%20was%20trying%20to%20post%20for%20last%20couple%20of%20days%20but%20was%20not%20able%20to%20post.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20I%20was%20using%20your%20listed%20suggestion%20for%20my%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20one%20small%20help%20again%20from%20you%2C%20attached%20is%20the%20excel%20sheet%20in%20which%20I%20am%20using%20your%20suggestion%2C%20however%2C%20I%20am%20able%20to%20use%20formula%20not%20in%20the%20same%20column%20in%20which%20count%20has%20to%20happen%2C%20I%20am%20able%20to%20use%20formula%20in%20cell%20other%20than%20column%20in%20which%20it%20is%20required.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20I%20have%20data%20in%20column%20A%20but%20formula%20I%20am%20able%20to%20use%20for%20Column%26nbsp%3B%20A%20is%20in%20Column%20B.%3C%2FP%3E%3CP%3EIs%20it%20possible%20to%20use%20the%20formula%20in%20the%20same%20column%20in%20which%20the%20data%20is%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20help.%3C%2FP%3E%3CP%3ESaurabh%20Khanna.%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-SUB%20id%3D%22lingo-sub-173474%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-173474%22%20slang%3D%22en-US%22%3EIt%20does%20not%20work%20because%20of%20circular%20reference%20problem.%20%3CBR%20%2F%3E%3CBR%20%2F%3EMy%20formula%20range%20starts%20from%20A1%20while%20you%20also%20want%20to%20use%20inside%20the%20same%20range.%3CBR%20%2F%3E%3CBR%20%2F%3ETo%20make%20this%20work%20you%20need%20to%20redefjne%20the%20starting%20row%20of%20your%20column%20A%20in%20the%20formula%20for%20example%20if%20your%20start%20of%20data%20starts%20from%20A4%20then%20the%20modified%20formula%20should%20be%20%3CBR%20%2F%3E%3DCOUNTBLANK(A%244%3AINDEX(A%3AA%2CSUMPRODUCT(MAX((A%3AA%26lt%3B%26gt%3B%22%22)*ROW(A%3AA)))))%3CBR%20%2F%3EThis%20should%20work.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-173448%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-173448%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20Mohammad%20-%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20agree%20with%20you%2C%20your%20formula%20gives%20the%20desired%20result%2C%20but%20when%20I%20try%20to%20use%20this%20formula%20in%20the%20same%20column%20in%20which%20I%20have%20the%20data%20I%20am%20getting%20an%20error%2C%20maybe%20because%20I%20am%20not%20able%20to%20modify%20the%20formula%20as%20per%20my%20need.%3C%2FP%3E%0A%3CP%3EI%20am%20attaching%20the%20excel%20sheet%2C%20were%20I%20have%20mentioned%20your%20formula%20in%20column%20other%20than%20A%20(in%20cell%20B2%20highlighted%20in%20green%20color)%2C%20but%20I%20want%20formula%20to%20work%20in%20the%20same%20data%20column%20that%20is%20in%20cell%20A2%20highlighted%20in%20yellow%20color.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20tried%20using%20the%20formula%20with%20couple%20of%20modifications%20but%20failed%2C%20can%20you%20guide%20me%2C%20maybe%20I%20am%20missing%20on%20using%20it%20properly%20%3A(%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-173141%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-173141%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F35679%22%20target%3D%22_blank%22%3E%40Haytham%20Amairah%3C%2FA%3E%2C%20thank%20you.%20When%20with%20wrap%3C%2FP%3E%0A%3CPRE%3E%3DIFERROR(COUNTBLANK(OFFSET(B1%2C0%2C0%2CAGGREGATE(14%2C6%2C(B%3AB%26lt%3B%26gt%3B%22%22)*ROW(B%3AB)%2C1)))%2C0)%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-173133%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-173133%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Saurabh%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EMy%20friends%20in%20previous%20replies%20give%20you%20some%20supposed%20solutions.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EPlease%20test%20their%26nbsp%3Bsolutions.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EEach%20formula%20gives%20you%20the%20same%26nbsp%3Bresult%2C%20except%20if%20the%20whole%20column%20is%20empty!%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIn%20this%20case%2C%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E's%20formula%20returns%20a%20%3CSTRONG%3E%23REF!%3C%2FSTRONG%3E%20error%2C%20but%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F24499%22%20target%3D%22_blank%22%3E%40Jamil%20Mohammad%3C%2FA%3E's%20formula%20counts%20all%20cells%20in%20the%20column%20which%20are%20all%20blanks.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-173112%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-173112%22%20slang%3D%22en-US%22%3E%3CP%3EAs%20variant%20that%20could%20be%3C%2FP%3E%0A%3CPRE%3E%3DCOUNTBLANK(OFFSET(A1%2C0%2C0%2CAGGREGATE(14%2C6%2C(A%3AA%26lt%3B%26gt%3B%22%22)*ROW(A%3AA)%2C1)))%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-173111%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-173111%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F129317%22%20target%3D%22_blank%22%3ESaurabh%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3Eyou%20can%20use%20my%20formula%20and%20then%20when%20you%20drag%20it%20to%20the%20left%2C%20it%20will%20also%20change%20the%20reference%2C%20as%20the%20formula%20uses%20relative%20references.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3DCOUNTBLANK(A%241%3AINDEX(A%3AA%2CSUMPRODUCT(MAX((A%3AA%26lt%3B%26gt%3B%22%22)*ROW(A%3AA)))))%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-173098%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-173098%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20Haytham%2C%20I%20had%20tried%20below%20formula%20earlier%2C%20and%20that%20is%20the%20issue%20which%20I%20had%20mentioned%20in%20my%20previous%20usage%20of%20INDIRECT%20function%20that%20column%20names%20are%20fixed%20and%20no%20longer%20remains%20dynamic.%3C%2FP%3E%0A%3CP%3ELike%20in%20below%20example%20column%20A%20that%20is%20%22A1%3AA%22%20is%20fixed%20in%20this%20formula%20under%20the%20INDIRECT%20function.%20Although%20this%20formula%20works%20perfectly%20Ok%20for%20column%20A%2C%20but%20if%20I%20want%20to%20paste%20this%20formula%20for%20many%20other%20columns%20then%20I%20have%20to%20manually%20change%20this%20input%20under%20the%20quotes%20for%20every%20column%20and%20that%20is%20where%20I%20have%20an%20issue%20with%20this%20formula%2C%20it%20no%20longer%20remains%20dynamic%20and%20does%20not%20change%20column%20reference%20when%20pasting%20in%20other%20columns%2C%20if%20you%20can%20guide%20me%20on%20how%20to%20resolve%20this%20issue%2C%20then%20it%20perfectly%20solves%20my%20issue%20%3A)%20and%20I%20will%20be%20very%20happy%20to%20learn%20this%20%3A)%3C%2FP%3E%0A%3CPRE%3E%3DCOUNTBLANK(INDIRECT(%22A1%3AA%22%26amp%3BSUMPRODUCT(MAX((A1%3AA6000%26lt%3B%26gt%3B%22%22)*ROW(A1%3AA6000)))))%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-173004%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-173004%22%20slang%3D%22en-US%22%3EIf%20you%20have%20many%20formulas%20then%20I%20don%E2%80%99t%20recommend%20using%20INDIRECT%20function%2C%20as%20it%20will%20slowdown%20your%20workbook.%20INDIRECT%20Is%20a%20volatile%20function.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-172998%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-172998%22%20slang%3D%22en-US%22%3E%3CP%3ESaurabh%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20join%20the%20value%20of%20SUMPRODUCT%20to%20the%20range%26nbsp%3B%3CSPAN%3E%22A1%3AA%22%20and%20then%20convert%20the%20result%20to%20an%20actual%20range%20by%20using%20INDIRECT%20as%20follows%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%3E%3DCOUNTBLANK(INDIRECT(%22A1%3AA%22%26amp%3BSUMPRODUCT(MAX((A1%3AA6000%26lt%3B%26gt%3B%22%22)*ROW(A1%3AA6000)))))%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20hope%20that%20helps%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-172997%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-172997%22%20slang%3D%22en-US%22%3EYou%20can%20try%20taking%20advantage%20of%20Index%20function%3CBR%20%2F%3E%3CBR%20%2F%3EYour%20dynamic%20range%20should%20be%20%3D%24A%241%3AINDEX(A%3AA%2CSUMPRODUCT(MAX((A%3AA%26lt%3B%26gt%3B%22%22)*ROW(A%3AA))))%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-172995%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-172995%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20Haytham%2C%20but%20unfortunately%20I%20will%20not%20be%20able%20to%20use%20this%20exactly%20the%20way%20in%20which%20I%20want%20to%20use.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHowever%2C%20I%20thought%20of%20following%20but%20failed%20on%20below%20also%2C%20just%20see%20if%20you%20have%20solution%20to%20my%20below%20question%20if%20you%20would%20have%20encountered.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20tried%20capturing%20the%20last%20row%20number%20of%20the%20non%20empty%20cell%20with%20the%20below%20formula%20(considering%20maximum%206000%20records%20that%20I%20will%20have%20at%20any%20time).%3C%2FP%3E%0A%3CP%3E%3DSUMPRODUCT(MAX((A1%3AA6000%26lt%3B%26gt%3B%22%22)*ROW(A1%3AA6000)))%3C%2FP%3E%0A%3CP%3ELet%20us%20assume%20with%20above%20formula%20I%20get%20value%20as%20390.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%2C%20with%20above%20formula%20I%20am%20getting%20the%20last%20non%20empty%20row%20number%20of%20a%20column.%3C%2FP%3E%0A%3CP%3ENo%20I%20want%20to%20pass%20this%20value%20from%20above%20formula%20into%20the%20Countblank%20function%20for%20the%20second%20half%20but%20only%20for%20the%20row%20number.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20example%3A%3C%2FP%3E%0A%3CP%3ECountblank(A1%3AA%3CFONT%20color%3D%22%23FF0000%22%3E%3CSTRONG%3E390%3C%2FSTRONG%3E%3C%2FFONT%3E)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20above%20formula%20I%20want%20to%20pass%20390%20number%20as%20a%20result%20of%20SUMPRODUCT%20function%20used%20above.%3C%2FP%3E%0A%3CP%3EI%20tried%20using%20the%20INDIRECT%20function%20for%20passing%20390%20value%2C%20but%20do%20not%20want%20to%20fix%20the%20column%20name%20because%20INDIRECT%20function%20requires%20column%20name%20to%20be%20fixed.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThus%20not%20able%20to%20solve%20my%20issue.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAny%20idea%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-172991%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20number%20of%20blank%20cells%20till%20last%20non%20empty%20cell%20in%20a%20column.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-172991%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Saurabh%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMy%20suggestion%20is%20set%20the%20range%20for%20one%20time%2C%20and%20make%20this%20range%20expandable%20somehow%20so%20that%20if%20you%20add%20a%20new%26nbsp%3Brecord%2C%20the%20range%20expands%20to%20include%20this%20new%20record.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20way%20to%20do%20that%20is%20to%20convert%20the%20normal%20range%20to%20Table%20and%20refer%20COUNTBLANK%20to%20a%20column%20in%20this%20table!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20find%20the%20attached%20file%20to%20test%20this%20suggestion.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Saurabh Khanna
Occasional Contributor

Hello -

 

I want to count number of blank cells till last non empty cell in a column but could not figure out how to do this, can you please help?

 

When I use Countblank formula, it takes an argument as range which should be known in the beginning itself which is a problem because then it becomes manual work to mention the range everytime as my column data (number of rows) can change many times, and different columns can  have different number of rows.

 

Is there a way to mention end limit of the range as row number of last non empty cell in that column?

 

Thank you in advance,

Saurabh Khanna.

 

 

23 Replies

Hi Saurabh,

 

My suggestion is set the range for one time, and make this range expandable somehow so that if you add a new record, the range expands to include this new record.

 

The way to do that is to convert the normal range to Table and refer COUNTBLANK to a column in this table!

 

Please find the attached file to test this suggestion.

Thank you Haytham, but unfortunately I will not be able to use this exactly the way in which I want to use.

 

However, I thought of following but failed on below also, just see if you have solution to my below question if you would have encountered.

 

I tried capturing the last row number of the non empty cell with the below formula (considering maximum 6000 records that I will have at any time).

=SUMPRODUCT(MAX((A1:A6000<>"")*ROW(A1:A6000)))

Let us assume with above formula I get value as 390.

 

Now, with above formula I am getting the last non empty row number of a column.

No I want to pass this value from above formula into the Countblank function for the second half but only for the row number.

 

For example:

Countblank(A1:A390)

 

In above formula I want to pass 390 number as a result of SUMPRODUCT function used above.

I tried using the INDIRECT function for passing 390 value, but do not want to fix the column name because INDIRECT function requires column name to be fixed.

 

Thus not able to solve my issue.

 

Any idea?

You can try taking advantage of Index function

Your dynamic range should be =$A$1:INDEX(A:A,SUMPRODUCT(MAX((A:A<>"")*ROW(A:A))))

Saurabh,

 

You can join the value of SUMPRODUCT to the range "A1:A" and then convert the result to an actual range by using INDIRECT as follows:

=COUNTBLANK(INDIRECT("A1:A"&SUMPRODUCT(MAX((A1:A6000<>"")*ROW(A1:A6000)))))

 

I hope that helps

 

If you have many formulas then I don’t recommend using INDIRECT function, as it will slowdown your workbook. INDIRECT Is a volatile function.

Thank you Haytham, I had tried below formula earlier, and that is the issue which I had mentioned in my previous usage of INDIRECT function that column names are fixed and no longer remains dynamic.

Like in below example column A that is "A1:A" is fixed in this formula under the INDIRECT function. Although this formula works perfectly Ok for column A, but if I want to paste this formula for many other columns then I have to manually change this input under the quotes for every column and that is where I have an issue with this formula, it no longer remains dynamic and does not change column reference when pasting in other columns, if you can guide me on how to resolve this issue, then it perfectly solves my issue :) and I will be very happy to learn this :)

=COUNTBLANK(INDIRECT("A1:A"&SUMPRODUCT(MAX((A1:A6000<>"")*ROW(A1:A6000)))))

 

Saurabh 

 

you can use my formula and then when you drag it to the left, it will also change the reference, as the formula uses relative references.

 

=COUNTBLANK(A$1:INDEX(A:A,SUMPRODUCT(MAX((A:A<>"")*ROW(A:A)))))

As variant that could be

=COUNTBLANK(OFFSET(A1,0,0,AGGREGATE(14,6,(A:A<>"")*ROW(A:A),1)))

 

Hi Saurabh,

 

My friends in previous replies give you some supposed solutions.

Please test their solutions.

 

Each formula gives you the same result, except if the whole column is empty!

In this case, @Sergei Baklan's formula returns a #REF! error, but @Jamil Mohammad's formula counts all cells in the column which are all blanks.

@Haytham Amairah, thank you. When with wrap

=IFERROR(COUNTBLANK(OFFSET(B1,0,0,AGGREGATE(14,6,(B:B<>"")*ROW(B:B),1))),0)

 

Hello Mohammad -

 

I agree with you, your formula gives the desired result, but when I try to use this formula in the same column in which I have the data I am getting an error, maybe because I am not able to modify the formula as per my need.

I am attaching the excel sheet, were I have mentioned your formula in column other than A (in cell B2 highlighted in green color), but I want formula to work in the same data column that is in cell A2 highlighted in yellow color.

 

I tried using the formula with couple of modifications but failed, can you guide me, maybe I am missing on using it properly :(

Solution
It does not work because of circular reference problem.

My formula range starts from A1 while you also want to use inside the same range.

To make this work you need to redefjne the starting row of your column A in the formula for example if your start of data starts from A4 then the modified formula should be
=COUNTBLANK(A$4:INDEX(A:A,SUMPRODUCT(MAX((A:A<>"")*ROW(A:A)))))
This should work.

 

Hello Jamil -

 

Your suggestion worked for me to a great extent.

I was trying to post for last couple of days but was not able to post.

 

And I was using your listed suggestion for my work.

 

I have one small help again from you, attached is the excel sheet in which I am using your suggestion, however, I am able to use formula not in the same column in which count has to happen, I am able to use formula in cell other than column in which it is required.

 

For example, I have data in column A but formula I am able to use for Column  A is in Column B.

Is it possible to use the formula in the same column in which the data is?

 

Thank you for your help.

Saurabh Khanna.

 

 

 

 

 

=COUNTBLANK(A$4:INDEX($A4:$A$500000,SUMPRODUCT(MAX(($A4:$A$500000<>"")*(ROW($A4:$A$500000)-ROW($A$4)+1)))))

or

=COUNTBLANK(OFFSET(A$4,0,0,AGGREGATE(14,6,1/($A4:$A$500000<>"")*(ROW($A4:$A$500000)-ROW($A$4)+1),1)))

 

Hello -

 

I am able to get the desired results and formula also works if i Past it for any column.

However, I noticed that if there is no data in a specified range for that column, then it does not work properly, can there be a way to treat this situation of no data as an exception?

 

Attaching the reference sheet with an example scenario.

 

Thank You,

Saurabh.

Hi Saurabh,

 

this is the formula to put in A2 and drag to the right .

 

Please note that it is an array formula, so it must be entered with holding Control+Shift+Enter.

 

=IFNA(COUNTBLANK(A3:INDEX(A3:A1048576,MATCH(2,1/(A3:A1048576<>"")))),0)

 

see attached workbook

Or

=IFNA(COUNTBLANK(A3:INDEX(A:A,LOOKUP(2,1/(A:A<>""),ROW(A:A)))),0)

(regular formula)

 

 

Hello -

 

When I downloaded your file, I am not getting result, it shows error.

I have taken screenshot "1" when file is downloaded and opened, and "2" when I pasted the formula in the cell.

 

Am i doing something wrong at me end, or is it Excel version compatibility issue; I am using Excel 2010?

 

Thank You,

Saurabh Khanna.

Hello -

 

When I downloaded your file, I am not getting result, it shows error.

I have taken screenshot "A" when file is downloaded and opened, and "B" when I pasted the formula in the cell(by Ctrl+Shift+Enter).

 

Am i doing something wrong at me end, or is it Excel version compatibility issue; I am using Excel 2010?

 

Thank You,

Saurabh Khanna.

it is because you are probably using Excel 2010 which does not have IFNA function.

 

SO i replaced is with IF ISNA 

 like this 

 

it is again with Control shift enter.  see attached

 

=IF(ISNA(COUNTBLANK(A3:INDEX(A3:A1048576,MATCH(2,1/(A3:A1048576<>""))))),0,COUNTBLANK(A3:INDEX(A3:A1048576,MATCH(2,1/(A3:A1048576<>"")))))

 

You may change IFNA on IFERROR

Many Thanks Jamil for your help, it works great.
Many Thanks Sergei for your help, it works great.
Related Conversations
Add 5 if a cell contains text "yes"
Titchard Family in Excel on
8 Replies
Counting in IF stmt
Jim-5 in Excel on
7 Replies