{"id":10452,"date":"2016-09-18T18:52:36","date_gmt":"2016-09-18T18:52:36","guid":{"rendered":"http:\/\/tayosolagbade.com\/sdnuggets\/?p=10452"},"modified":"2016-09-18T18:52:36","modified_gmt":"2016-09-18T18:52:36","slug":"excelvb-case-study-code-to-hide-the-row-for-a-cell-that-contains-a-specific-text-string","status":"publish","type":"post","link":"http:\/\/tayosolagbade.com\/sdnuggets\/excelvb-case-study-code-to-hide-the-row-for-a-cell-that-contains-a-specific-text-string\/","title":{"rendered":"ExcelVB Case Study: Code to hide the row for a cell that contains a specific text string"},"content":{"rendered":"<blockquote><p><span class=\"_3oh-\">\"Dear sir, Can you have a vb code in the condition that i want to hide (not to delete) the entire row if a particular cell has \"katol\".......... Please do it for me sir.<\/span>\"<\/p><\/blockquote>\n<p><a href=\"http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin.png\" rel=\"attachment wp-att-10459\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10459\" src=\"http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin.png\" alt=\"\" width=\"403\" height=\"184\" srcset=\"http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin.png 403w, http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin-300x137.png 300w, http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin-150x68.png 150w\" sizes=\"auto, (max-width: 403px) 100vw, 403px\" \/><\/a><\/p>\n<p><i>I created<\/i><i> this Excel-VB coding tutorial in response to the above request from Pravin which he sent via my Facebook page on Sunday 18th Sept 2016 as a case study for members of my Excel Heaven Visual Basic Automation Club<\/i><\/p>\n<p><i> [NB: By way of interest, <a href=\"http:\/\/excelheaven.tayosolagbade.com\/?p=394\" target=\"_blank\">I've had to respond to Pravin's request once before in this same manner - click here<\/a>. At the bottom of this post, I reproduce a detailed message I initially sent to him, explaining why I may find it difficult to respond to future requests of this nature from him - pointing out a useful forum he can visit to get reliable answers to his queries.]<br \/>\n<\/i><\/p>\n<h3>Below: A screenshot of the MS Excel Worksheet I formatted the code driven interface to fit into [<a href=\"http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin.xlsm\" target=\"_blank\">Click here<\/a> to download the workbook with the code]<\/h3>\n<p><a href=\"http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin-case-study.png\" rel=\"attachment wp-att-10461\"><img decoding=\"async\" class=\"alignnone size-full wp-image-10461\" src=\"http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin-case-study.png\" alt=\"pravin-case-study\" width=\"580\" srcset=\"http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin-case-study.png 1204w, http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin-case-study-300x241.png 300w, http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin-case-study-768x617.png 768w, http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin-case-study-1024x822.png 1024w, http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin-case-study-150x120.png 150w\" sizes=\"(max-width: 1204px) 100vw, 1204px\" \/><\/a><\/p>\n<blockquote>\n<h3><b>Steps to follow<\/b><\/h3>\n<p>In order to to have a cell's row hide and unhide based \u00a0on the occurrence of a specific value,\u00a0 it's best to\u00a0 write code for it in a <b>Worksheet_Change <\/b>event:<\/p>\n<ol>\n<li>Open a blank MS Excel workbook and click on the <b>Worksheet Tab labeled Sheet1<\/b> to select it<\/li>\n<li>Next Press Alt+F11 to access the Visual Basic Editor<\/li>\n<li>In the Project Explorer Window, double click <b>Sheet1<\/b> to open that Worksheet's code window<\/li>\n<\/ol>\n<p><b>TIP:\u00a0 You can compress steps 2 and 3 into one by simply right clicking on the Sheet1 Worksheet tab after step 1 and clicking VIEW CODE on the shortcut menu that appears, to open the <\/b>Worksheet's code window<\/p>\n<ol start=\"4\">\n<li>Copy and paste the code below into the Worksheet's code window<\/li>\n<\/ol>\n<p><b>====Starts====<\/b><\/p>\n<p><b>Private Sub Worksheet_Change(ByVal Target As Range)<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0 If Range(\"CheckValue\").Value = \"Katol\" Then<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Range(\"CheckValue\").EntireRow.Hidden = True<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0 ElseIf Range(\"CheckValue\").Value <> \"Katol\" Then<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Range(\"CheckValue\").EntireRow.Hidden = False<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0 End If<\/b><\/p>\n<p><b>End Sub<\/b><\/p>\n<p><b>====Ends====<\/b><\/p>\n<ol start=\"5\">\n<li>Recall from previous tutorials that I use range names to identify Excel objects I want to use code to refer to.<\/li>\n<\/ol>\n<p>So, in the case of Pravin's example, I've named the cell in which \"Katol\" appears, as \"CheckValue\" (the yellow coloured cell).<\/p><\/blockquote>\n<ol start=\"6\">\n<li>\n<blockquote><p>Note the buttons to the top left of this frame - for posting the test string into the yellow cell and for erasing the cell's contents. The code behind them is reproduced in the explanation boxes below them.<\/p><\/blockquote>\n<\/li>\n<\/ol>\n<p>[<a href=\"http:\/\/tayosolagbade.com\/sdnuggets\/wp-content\/uploads\/2016\/09\/pravin.xlsm\" target=\"_blank\">Click here<\/a> to download the workbook with the code]<\/p>\n<h3>Below: D<i>etailed message I initially sent to Pravin this evening, explaining why I may find it difficult to respond to future requests of this nature from him.<\/i><\/h3>\n<p><i>I pointed him to a useful forum he can visit to get reliable answers to his queries. I reproduce it here in order to give the reader greater insight into how I do what I do, as it relates to coaching members of my Excel-VB club while working as a multi-discplinary expert.<\/i><\/p>\n<blockquote><p>Hi Pravin.<\/p>\n<p>It would be my pleasure to send you the code to hide a cell or range. But like I told you before, I do a lot of things that require my serious attention. For instance right now, I'm modifying my Excel-VB Poultry Farm Manager for a new buyer who requested changes, and after that I need to prepare 2 newsletters and also write 4 articles for a UK client. I simply do not have the kind of time others do, to respond to requests of this nature.<\/p>\n<p>In other words, I'm NOT your usual Excel expert who does only Excel based work. I am a multipreneur, engaged in various vocations, that take my time.<\/p>\n<p>But I have a vision to build Excel-VB developers in my primary target market of Nigeria\/Africa. I happen to think YOU have lots of experts in your country or region you can reach out to.<\/p>\n<p>To do what I do out here, I feel if I am to add value to someone, it is best that I empower him\/her to be able, even if over time, to find out how to do such stuff and others s\/he may desire to do, by him or herself<\/p>\n<p>It is for this reason that I prefer to challenge any persons who reach out to me to commit to EXPERIENTIAL LEARNING. I do NOT believe in TELLING people how to do things. Instead i believe in guiding them to discover how to write their own code.<\/p>\n<p>So, responding to requests like yours tend to be difficult for me, especially since you are NOT in my coaching club. Unlike what obtains in YOUR country and other non-African nations, access to the Internet here is such that I simply cannot make myself available to respond to all requests. It not only costs a lot, but it also tends to be erratic in nature - plus I have a lot I'm doing.<\/p>\n<p>Most importantly, and I have told you this before, there are people who run websites who invite visitors to send them such requests. A good example is <a href=\"http:\/\/www.mrexcel.com\/forum\/index.php\" target=\"_blank\">http:\/\/www.mrexcel.com\/forum\/index.php<\/a> - the forum at Mr Excel. There you can register and post ANY questions you have for experts to answer.<\/p>\n<p>In my case, I am primarily focused on building Excel-VB skills in niche markets in MY country, and my strategy does NOT require that I make myself available to respond to all comers, much as I would like to.<\/p>\n<p>Instead, I have to focus on serving people within my network, based on their specific needs as business users. That is why my Excel-VB club is my priority.<\/p>\n<p>I will therefore end by telling you what I have told you before:<\/p>\n<p>I will make out time to create a tutorial based on what you specified above for you, which I will use to teach my club members, featuring YOU in my broadcast to them.<\/p>\n<p>However, AFTER I do this, let me make it clear that I will NOT be able to take on ANY requests you make in future - except you choose to join my Excel-VB Club.<\/p>\n<p>I hope my offer is acceptable to you. If not, I advise that you visit <a href=\"http:\/\/www.mrexcel.com\/forum\/index.php\" target=\"_blank\">http:\/\/www.mrexcel.com\/forum\/index.php<\/a> and post your question there.<\/p>\n<p>Maybe in future I'll be able to re-invent the way I work, to take on all comers. For now, this is the best I can do.<\/p>\n<p>With kindest regards,<\/p>\n<p>Tayo<\/p><\/blockquote>\n<h3>Related Article<\/h3>\n<p><a title=\"Permanent Link to Download MS Excel-VB Screen shot Demonstration Video Tutorials for Tayo Solagbade\u2019s Introduction to Excel-VB Automation Workshop Held on Sat 19th March 2016 in Lagos-Nigeria [Includes video recorded in response to last week\u2019s request for Excel-VB coding help from a business user in India]\" href=\"http:\/\/tayosolagbade.com\/sdnuggets\/download-ms-excel-vb-screen-shot-demonstration-video-tutorials-for-tayo-solagbades-introduction-to-excel-vb-automation-workshop-held-on-sat-19th-march-2016-in-lagos-nigeria-includes-video-recorded\/\" rel=\"bookmark\">Download MS Excel-VB Screen shot Demonstration Video Tutorials for Tayo Solagbade\u2019s Introduction to Excel-VB Automation Workshop Held on Sat 19th March 2016 in Lagos-Nigeria [Includes video recorded in response to last week\u2019s request for Excel-VB coding help from a business user in India]<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\"Dear sir, Can you have a vb code in the condition that i want to hide (not to delete) the entire row if a particular cell has \"katol\".......... Please do it for me sir.\" I created this Excel-VB coding tutorial in response to the above request from Pravin which he sent via my Facebook page [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,1375,266,1440,10],"tags":[2502,2501],"class_list":["post-10452","post","type-post","status-publish","format-standard","hentry","category-employeescareer-persons","category-excel-vb-solutions","category-my-dn-travel-news","category-recommended-websites-articles","category-self-development","tag-code-to-hide-the-row-for-a-cell-that-contains-a-specific-text-string","tag-excelvb-case-study"],"aioseo_notices":[],"views":1143,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/tayosolagbade.com\/sdnuggets\/wp-json\/wp\/v2\/posts\/10452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/tayosolagbade.com\/sdnuggets\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tayosolagbade.com\/sdnuggets\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tayosolagbade.com\/sdnuggets\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tayosolagbade.com\/sdnuggets\/wp-json\/wp\/v2\/comments?post=10452"}],"version-history":[{"count":3,"href":"http:\/\/tayosolagbade.com\/sdnuggets\/wp-json\/wp\/v2\/posts\/10452\/revisions"}],"predecessor-version":[{"id":10463,"href":"http:\/\/tayosolagbade.com\/sdnuggets\/wp-json\/wp\/v2\/posts\/10452\/revisions\/10463"}],"wp:attachment":[{"href":"http:\/\/tayosolagbade.com\/sdnuggets\/wp-json\/wp\/v2\/media?parent=10452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tayosolagbade.com\/sdnuggets\/wp-json\/wp\/v2\/categories?post=10452"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tayosolagbade.com\/sdnuggets\/wp-json\/wp\/v2\/tags?post=10452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}