{"id":15084,"date":"2021-12-17T15:59:28","date_gmt":"2021-12-17T15:59:28","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=15084"},"modified":"2021-12-17T15:59:46","modified_gmt":"2021-12-17T15:59:46","slug":"solved-how-to-add-multiple-vba-codes-in-one-sheet-code-view","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/office\/how-to-add-multiple-vba-codes-in-one-sheet-code-view\/20229.html","title":{"rendered":"Solved How To Add Multiple VBA Codes In One Sheet Code View"},"content":{"rendered":"<p>sir, I want to highlight excel cell by selecting different cell. for example:<br \/>\nhighlight cell b2 when cell c2 is selected and highlight cell b2 when cell d2 is selected and highlight cell b2 when cell e2 is selected and like so on&#8230;&#8230;<\/p>\n<p>the following code is working for highlighting the left\/right cell but I want to have a multiple conditions.<\/p>\n<p>Private Sub Worksheet_SelectionChange(ByVal target As Range)<br \/>\nOn Error Resume Next<br \/>\n&#8216;Get address to reset highlighting<br \/>\noldTarget = Range(&#8220;C2&#8221;)<br \/>\n&#8216;Reset highlighting<br \/>\nRange(oldTarget).Interior.ColorIndex = xlNone<br \/>\n&#8216;Highlight cell -1 columns to the right<br \/>\ntarget.Offset(0, -1).Interior.ColorIndex = 6<br \/>\n&#8216;Store highlighted cell address for use next time<br \/>\nRange(&#8220;C2&#8221;) = target.Offset(0, -1).Address<br \/>\nEnd Sub<\/p>\n<p align=\"right\"><span style=\"font-size: xx-small;\"><i>message edited by Azan<\/i><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":42},"question-category":[53],"question_tags":[],"class_list":["post-15084","question","type-question","status-publish","hentry","question-category-office"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/15084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=15084"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=15084"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=15084"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=15084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}