{"id":11065,"date":"2025-01-15T01:10:55","date_gmt":"2025-01-15T01:10:55","guid":{"rendered":"https:\/\/blog.ezworkapp.com\/index.php\/2025\/01\/15\/cach-tam-thoi-ngung-hoat-dong-cua-macro-de-chon-dai-o\/"},"modified":"2025-01-15T01:10:55","modified_gmt":"2025-01-15T01:10:55","slug":"cach-tam-thoi-ngung-hoat-dong-cua-macro-de-chon-dai-o","status":"publish","type":"post","link":"https:\/\/blog.ezworkapp.com\/index.php\/2025\/01\/15\/cach-tam-thoi-ngung-hoat-dong-cua-macro-de-chon-dai-o\/","title":{"rendered":"C\u00e1ch t\u1ea1m th\u1eddi ng\u1eebng ho\u1ea1t \u0111\u1ed9ng c\u1ee7a macro \u0111\u1ec3 ch\u1ecdn d\u1ea3i \u00f4"},"content":{"rendered":"<div class=\"uk-panel uk-margin\" id=\"template-dQf5b79p#1\">\n<p style=\"text-align: justify\">D\u01b0\u1edbi \u0111\u00e2y l\u00e0 b\u00ed k\u00edp l\u00e0m c\u00e1ch n\u00e0o \u0111\u1ec3 macro ng\u1eebng ho\u1ea1t \u0111\u1ed9ng t\u1ea1m th\u1eddi sao cho ng\u01b0\u1eddi d\u00f9ng c\u00f3 th\u1ec3 l\u1ef1a ch\u1ecdn \u0111\u01b0\u1ee3c d\u1ea3i \u00f4 trong Excel. M\u1eb9o nh\u1ecf \u1edf \u0111\u00e2y l\u00e0 s\u1eed d\u1ee5ng h\u00e0m InputBox trong m\u1ee5c Application.<\/p>\n<p style=\"text-align: justify\">L\u01b0u \u00fd: B\u1ea1n kh\u00f4ng n\u00ean nh\u1ea7m l\u1eabn v\u1edbi h\u00e0m InputBox c\u1ee7a VBA. Tuy c\u00f3 c\u00f9ng t\u00ean g\u1ecdi nh\u01b0ng b\u1ea3n ch\u1ea5t \u0111\u00e2y l\u00e0 2 h\u00e0m kh\u00e1c nhau.<\/p>\n<p style=\"text-align: justify\">L\u1ec7nh Sub d\u01b0\u1edbi \u0111\u00e2y s\u1ebd cho ph\u00e9p ng\u01b0\u1eddi d\u00f9ng t\u1ea1m th\u1eddi ng\u1eebng ho\u1ea1t \u0111\u1ed9ng c\u1ee7a macro \u0111\u1ec3 l\u1ef1a ch\u1ecdn d\u1ea3i \u00f4.<\/p>\n<p style=\"text-align: justify\"><em>Sub GetUserRange()<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0 Dim UserRange As Range\u00a0\u00a0<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0 Output = 565<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0 Prompt = \u201cSelect a cell for the output.\u201d<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0 Title = \u201cSelect a cell\u201d<\/em><\/p>\n<div class=\"code-block code-block-2\" style=\"margin: 8px 0;clear: both\">\n<div class=\"ad-inserterpro\">\n<a href=\"https:\/\/hocexcel.online\/course\/preview\/vba101-tu-dong-hoa-excel-voi-lap-trinh-vba-cho-nguoi-moi-bat-dau\"><br \/>\n<img decoding=\"async\" src=\"http:\/\/blog.ezworkapp.com\/wp-content\/uploads\/2025\/01\/vba101_92019-nho-31.gif\" title=\"vba101_92019-nho-31\"><br \/>\n<\/a>\n<\/div>\n<\/div>\n<div class=\"code-block code-block-1\" style=\"margin: 8px 0;clear: both\">\n<div class=\"ad-inserterpro\">\n<a href=\"https:\/\/hocexcel.online\/course\/preview\/ex101-excel-tu-co-ban-den-chuyen-gia-danh-cho-nguoi-di-lam\"><br \/>\n<img decoding=\"async\" src=\"http:\/\/blog.ezworkapp.com\/wp-content\/uploads\/2025\/01\/ex101_92019-nho-254.gif\" title=\"ex101_92019-nho-254\"><br \/>\n<\/a>\n<\/div>\n<\/div>\n<p style=\"text-align: justify\"><em>\u2018\u00a0\u00a0 Display the Input Box<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0 On Error Resume Next<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0 Set UserRange = Application.InputBox( _<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Prompt:=Prompt, _<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Title:=Title, _<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Default:=ActiveCell.Address, _<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Type:=8) \u2018Range selection<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u2018\u00a0\u00a0 Was the Input Box canceled?<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0 If UserRange Is Nothing Then<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MsgBox \u201cCanceled.\u201d<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0 Else<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 UserRange.Range(\u201cA1\u201d) = Output<\/em><\/p>\n<p style=\"text-align: justify\"><em>\u00a0\u00a0\u00a0 End If<\/em><\/p>\n<p style=\"text-align: justify\"><em>End Sub<\/em><\/p>\n<p style=\"text-align: justify\">H\u1ed9p tho\u1ea1i \u0111i\u1ec1n th\u00f4ng tin s\u1ebd c\u00f3 d\u1ea1ng nh\u01b0 sau:<\/p>\n<figure id=\"attachment_8460\" aria-describedby=\"caption-attachment-8460\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8460\" src=\"http:\/\/blog.ezworkapp.com\/wp-content\/uploads\/2025\/01\/inputbox.gif\" width=\"600\" height=\"348\" title=\"inputbox\"><figcaption id=\"caption-attachment-8460\" class=\"wp-caption-text\">H\u1ed9p tho\u1ea1i \u0111i\u1ec1n th\u00f4ng tin<\/figcaption><\/figure>\n<p style=\"text-align: justify\">M\u1ea5u ch\u1ed1t th\u00e0nh c\u00f4ng c\u1ee7a c\u00e2u l\u1ec7nh n\u00e0y ch\u00ednh l\u00e0 vi\u1ec7c t\u00f9y ch\u1ec9nh t\u00ednh n\u0103ng \u201cType\u201d \u00a0\u0111\u01b0\u1ee3c \u0111\u1eb7t \u1edf gi\u00e1 tr\u1ecb\u00a0l\u00e0 8. Ngo\u00e0i ra b\u1ea1n c\u0169ng n\u00ean l\u01b0u \u00fd th\u00eam v\u1ec1 c\u00e1ch s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh \u201cOn Error Resume Next\u201d. L\u1ec7nh n\u00e0y s\u1ebd t\u1ef1 \u0111\u1ed9ng l\u1edd \u0111i l\u1ed7i g\u1eb7p ph\u1ea3i n\u1ebfu nh\u01b0 ng\u01b0\u1eddi d\u00f9ng click v\u00e0o l\u1ef1a ch\u1ecdn \u201cCancel\u201d. Khi \u0111\u00f3, t\u00ednh n\u0103ng \u201cUserRange\u201d s\u1ebd kh\u00f4ng \u0111\u01b0\u1ee3c k\u00edch ho\u1ea1t. Sau \u0111\u00f3 th\u00f4ng b\u00e1o\u00a0s\u1ebd hi\u1ec7n l\u00ean v\u1edbi d\u00f2ng ch\u1eef \u201cCanceled\u201d. Ch\u1ec9 khi ng\u01b0\u1eddi d\u00f9ng click v\u00e0o l\u1ef1a ch\u1ecdn \u201cOK\u201d, macro m\u1edbi ti\u1ebfp t\u1ee5c ho\u1ea1t \u0111\u1ed9ng tr\u1edf l\u1ea1i.<\/p>\n<p style=\"text-align: justify\">M\u1ed9t l\u01b0u \u00fd n\u1eefa, b\u1ea1n kh\u00f4ng c\u1ea7n ph\u1ea3i qu\u00e1 b\u1eadn t\u00e2m v\u1ec1 chi\u1ec1u d\u00e0i d\u1ea3i \u00f4 bao nhi\u00eau th\u00ec h\u1ee3p l\u00fd. Excel s\u1ebd t\u1ef1 t\u00ednh to\u00e1n thay cho b\u1ea1n.<\/p>\n<p style=\"text-align: justify\">C\u1ea3nh b\u00e1o: H\u00e3y \u0111\u1ea3m b\u1ea3o b\u1ea1n \u0111\u00e3 b\u1eadt t\u00ednh n\u0103ng \u201cScreenUpdating\u201d l\u00ean. N\u1ebfu kh\u00f4ng b\u1ea1n s\u1ebd kh\u00f4ng th\u1ec3 ch\u1ecdn \u0111\u01b0\u1ee3c b\u1ea5t k\u1ef3 \u00f4 t\u00ednh n\u00e0o c\u1ea3.<\/p>\n<\/div>\n<div class=\"uk-panel uk-margin uk-width-xlarge\">\n<p>Click \u0111\u0103ng k\u00fd h\u1ecdc t\u1ea1i:<\/p>\n<p><a href=\"http:\/\/blog.ezworkapp.com\/khoa-hoc\" target=\"_blank\" rel=\"noopener\">T\u1ea5t c\u1ea3 kho\u00e1 h\u1ecdc\u00a0<span>\ud83d\udcd6<\/span><\/a><\/p>\n<p><a href=\"http:\/\/blog.ezworkapp.com\/huong-dan-kich-hoat-khoa-hoc-tai-hoc-excel-online.html\" target=\"_blank\" rel=\"noopener\">H\u01b0\u1edbng d\u1eabn k\u00edch ho\u1ea1t<\/a><\/p>\n<p>HKD H\u1ecdc Excel Online<br \/>S\u1ed1 \u0110K: 17A80048102<\/p>\n<\/div>\n<div class=\"uk-panel uk-text-small uk-margin uk-margin-remove-bottom uk-text-center\">\n<p>\u00a9  document.currentScript.insertAdjacentHTML(&#8216;afterend&#8217;, &#8221; + new Intl.DateTimeFormat(document.documentElement.lang, {year: &#8216;numeric&#8217;}).format() + &#8221;);  H\u1ecdc Excel Online. All rights reserved.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<div class=\"ad-inserterpro\">\n<a href=\"https:\/\/hocexcel.online\/course\/preview\/vba101-tu-dong-hoa-excel-voi-lap-trinh-vba-cho-nguoi-moi-bat-dau\"><br \/>\n<img decoding=\"async\" src=\"http:\/\/blog.ezworkapp.com\/wp-content\/uploads\/2025\/01\/vba101_92019-nho-31.gif\"><br \/>\n<\/a>\n<\/div>\n","protected":false},"author":1,"featured_media":11066,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-11065","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-excel-co-ban"],"_links":{"self":[{"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/posts\/11065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/comments?post=11065"}],"version-history":[{"count":0,"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/posts\/11065\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/media\/11066"}],"wp:attachment":[{"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/media?parent=11065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/categories?post=11065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/tags?post=11065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}