{"id":5030,"date":"2022-05-12T03:02:00","date_gmt":"2022-05-11T18:02:00","guid":{"rendered":"https:\/\/okamurax.com\/?p=5030"},"modified":"2023-03-15T20:15:27","modified_gmt":"2023-03-15T11:15:27","slug":"vba-worksheet_selectionchange","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=5030","title":{"rendered":"VBA Worksheet_Change\/SelectionChange"},"content":{"rendered":"<p>\u30af\u30ea\u30c3\u30af\u3057\u305f\u30bb\u30eb\u306e\u5024\u3092\u53d6\u5f97<\/p>\n<pre class=\"lang:vb decode:true \">Private Sub Worksheet_SelectionChange(ByVal Target As Range)\r\n\r\nOn Error Resume Next\r\n\r\n' \u30af\u30ea\u30c3\u30af\u30bb\u30eb\u306e\u5024\u30c1\u30a7\u30c3\u30af\r\n\r\nIf Target.Value &lt;&gt; \"[\u524a\u9664]\" Then Exit Sub\r\n\r\n' \u30af\u30ea\u30c3\u30af\u30bb\u30eb\u306e\u7bc4\u56f2\u30c1\u30a7\u30c3\u30af\r\n\r\nIf Target.Row &lt; 2 Then Exit Sub\r\nIf Target.Column &lt;&gt; 8 Then Exit Sub\r\n\r\n' \u30af\u30ea\u30c3\u30af\u884c\u306e\u5024\u3092\u53d6\u5f97\r\n\r\nid = ActiveSheet.Cells(Target.Row, 1).Value\r\n\r\nEnd Sub<\/pre>\n<p>\u30bb\u30eb\u306e\u5024\u306e\u5909\u66f4\u3092\u30c1\u30a7\u30c3\u30af<\/p>\n<pre class=\"lang:vb decode:true \">Dim beforeValue As Variant\r\n\r\nPrivate Sub Worksheet_Change(ByVal Target As Range)\r\n\r\nOn Error Resume Next\r\n\r\nIf Target.Column &lt;&gt; 6 Then Exit Sub\r\n\r\nIf beforeValue &lt;&gt; Target.Value Then\r\n  MsgBox \"\u5909\u66f4\u3055\u308c\u307e\u3057\u305f\" &amp; Chr(13) &amp; Target.Value\r\nEnd If\r\n\r\nEnd Sub\r\n\r\nPrivate Sub Worksheet_SelectionChange(ByVal Target As Range)\r\n\r\nOn Error Resume Next\r\n\r\nIf Target.Column &lt;&gt; 6 Then Exit Sub\r\n\r\nbeforeValue = Target.Value\r\n\r\nEnd Sub\r\n<\/pre>\n<p>UserForm\u304b\u3089\u30b7\u30fc\u30c8\u306eSelectionChange\u3092\u62fe\u3046\u5834\u5408<\/p>\n<pre class=\"lang:vb decode:true \">Private WithEvents e As Application\r\n\r\nSub e_SheetSelectionChange(ByVal w As Object, ByVal Target As Range)\r\n\r\nIf ToggleButton1.Value = False Then Exit Sub\r\n\r\n' w.Parent.Name ' \u30d6\u30c3\u30af\u540d\r\n' w.Name ' \u30b7\u30fc\u30c8\u540d\r\n' Target.Address ' \u9078\u629e\u7bc4\u56f2\r\n' Target.Item(1).Address ' \u9078\u629e\u7bc4\u56f2\u306e\u5de6\u4e0a\r\n\r\nDebug.Print Target.Item(1).Value\r\n\r\nr = Target.Item(1).Row\r\nTextBox19.Text = w.Cells(r, 1).Value\r\n\r\nEnd Sub\r\n\r\nSub UserForm_Initialize()\r\n\r\nSet e = Application\r\n\r\nEnd Sub<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30af\u30ea\u30c3\u30af\u3057\u305f\u30bb\u30eb\u306e\u5024\u3092\u53d6\u5f97 Private Sub Worksheet_SelectionChange(ByVal Target As Range) On Error Resume Next &#8216; \u30af\u30ea\u30c3\u30af\u30bb\u30eb\u306e\u5024\u30c1\u30a7\u30c3\u30af &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=5030\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;VBA Worksheet_Change\/SelectionChange&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[5],"class_list":["post-5030","post","type-post","status-publish","format-standard","hentry","category-1","tag-vba"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/5030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5030"}],"version-history":[{"count":5,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/5030\/revisions"}],"predecessor-version":[{"id":5646,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/5030\/revisions\/5646"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}