{"id":2031,"date":"2024-12-02T06:50:34","date_gmt":"2024-12-02T06:50:34","guid":{"rendered":"https:\/\/blog.ezworkapp.com\/index.php\/2024\/12\/02\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau\/"},"modified":"2024-12-02T06:50:34","modified_gmt":"2024-12-02T06:50:34","slug":"huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau","status":"publish","type":"post","link":"https:\/\/blog.ezworkapp.com\/index.php\/2024\/12\/02\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau\/","title":{"rendered":"H\u01af\u1edaNG D\u1eaaN VBA C\u01a0 B\u1ea2N CHO NG\u01af\u1edcI M\u1edaI B\u1eaeT \u0110\u1ea6U"},"content":{"rendered":"<div class=\"uk-panel uk-margin\" id=\"template-dQf5b79p#1\">\n<p><em><span style=\"font-weight: 400\">Trong b\u00e0i h\u01b0\u1edbng d\u1eabn VBA d\u01b0\u1edbi \u0111\u00e2y, <a href=\"http:\/\/blog.ezworkapp.com\/\"><strong>H\u1ecdc Excel Online<\/strong><\/a> s\u1ebd gi\u1edbi thi\u1ec7u b\u1ea1n <strong>kh\u00f3a h\u1ecdc VBA c\u01a1 b\u1ea3n<\/strong> cho ng\u01b0\u1eddi m\u1edbi b\u1eaft \u0111\u1ea7u, c\u1ee5 th\u1ec3 l\u00e0 t\u1eadp trung v\u00e0o vi\u1ec7c t\u1ea1o macro Excel. \u0110\u1ec3 hi\u1ec3u r\u00f5 h\u01a1n b\u1ea1n c\u00f3 th\u1ec3 xem qua m\u1ed9t v\u00e0i v\u00ed d\u1ee5 trong b\u00e0i vi\u1ebft v\u00e0 th\u1ef1c hi\u1ec7n theo.<\/span><\/em><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_61 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<p class=\"ez-toc-title\">Xem nhanh<\/p>\n<p><label for=\"ez-toc-cssicon-toggle-item-674d58b91dbda\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><\/span><\/span><\/label><\/p>\n<nav>\n<ul class=\"ez-toc-list ez-toc-list-level-1 \">\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Cac_thuat_ngu_co_ban_su_dung_trong_bai_viet\" title=\"C\u00e1c thu\u1eadt ng\u1eef c\u01a1 b\u1ea3n s\u1eed d\u1ee5ng trong b\u00e0i vi\u1ebft\u00a0\">C\u00e1c thu\u1eadt ng\u1eef c\u01a1 b\u1ea3n s\u1eed d\u1ee5ng trong b\u00e0i vi\u1ebft\u00a0<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Thu_thuat_khi_hoat_dong_VBA\" title=\"Th\u1ee7 thu\u1eadt khi ho\u1ea1t \u0111\u1ed9ng VBA\">Th\u1ee7 thu\u1eadt khi ho\u1ea1t \u0111\u1ed9ng VBA<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Tao_module\" title=\"T\u1ea1o module\">T\u1ea1o module<\/a>\n<ul class=\"ez-toc-list-level-3\">\n<li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Hoat_dong_1\" title=\"Ho\u1ea1t \u0111\u1ed9ng 1:\">Ho\u1ea1t \u0111\u1ed9ng 1:<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Ket_thuc_hoat_dong_1\" title=\"K\u1ebft th\u00fac ho\u1ea1t \u0111\u1ed9ng 1\">K\u1ebft th\u00fac ho\u1ea1t \u0111\u1ed9ng 1<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Hoat_dong_2\" title=\"Ho\u1ea1t \u0111\u1ed9ng 2\">Ho\u1ea1t \u0111\u1ed9ng 2<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Ket_thuc_hoat_dong_2\" title=\"K\u1ebft th\u00fac ho\u1ea1t \u0111\u1ed9ng 2\">K\u1ebft th\u00fac ho\u1ea1t \u0111\u1ed9ng 2<\/a><\/li>\n<\/ul>\n<\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Cach_su_dung_Sub\" title=\"C\u00e1ch s\u1eed d\u1ee5ng Sub\">C\u00e1ch s\u1eed d\u1ee5ng Sub<\/a>\n<ul class=\"ez-toc-list-level-3\">\n<li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Hoat_dong_3\" title=\"Ho\u1ea1t \u0111\u1ed9ng 3\">Ho\u1ea1t \u0111\u1ed9ng 3<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Ket_thuc_hoat_dong_3\" title=\"K\u1ebft th\u00fac ho\u1ea1t \u0111\u1ed9ng 3.\">K\u1ebft th\u00fac ho\u1ea1t \u0111\u1ed9ng 3.<\/a><\/li>\n<\/ul>\n<\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Dien_gia_tri_vao_o\" title=\"\u0110i\u1ec1n gi\u00e1 tr\u1ecb v\u00e0o \u00f4\">\u0110i\u1ec1n gi\u00e1 tr\u1ecb v\u00e0o \u00f4<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Cac_o_trong_cac_trang_tinh_khac_nhau\" title=\"C\u00e1c \u00f4 trong c\u00e1c trang t\u00ednh kh\u00e1c nhau\">C\u00e1c \u00f4 trong c\u00e1c trang t\u00ednh kh\u00e1c nhau<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Ten_ma_cua_trang_tinh\" title=\"T\u00ean m\u00e3 c\u1ee7a trang t\u00ednh\">T\u00ean m\u00e3 c\u1ee7a trang t\u00ednh<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Lenh_With\" title=\"L\u1ec7nh With\">L\u1ec7nh With<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Thut_le_voi_cac_dong_ma\" title=\"Th\u1ee5t l\u1ec1 v\u1edbi c\u00e1c d\u00f2ng m\u00e3\">Th\u1ee5t l\u1ec1 v\u1edbi c\u00e1c d\u00f2ng m\u00e3<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Sao_chep_gia_tri_giua_nhieu_o\" title=\"Sao ch\u00e9p gi\u00e1 tr\u1ecb gi\u1eefa nhi\u1ec1u \u00f4\">Sao ch\u00e9p gi\u00e1 tr\u1ecb gi\u1eefa nhi\u1ec1u \u00f4<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Chuyen_doi_vung_du_lieu_o\" title=\"Chuy\u1ec3n \u0111\u1ed5i v\u00f9ng d\u1eef li\u1ec7u \u00f4\">Chuy\u1ec3n \u0111\u1ed5i v\u00f9ng d\u1eef li\u1ec7u \u00f4<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Cach_su_dung_cac_bien\" title=\"C\u00e1ch s\u1eed d\u1ee5ng c\u00e1c bi\u1ebfn\">C\u00e1ch s\u1eed d\u1ee5ng c\u00e1c bi\u1ebfn<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Khai_bao_cac_bien\" title=\"Khai b\u00e1o c\u00e1c bi\u1ebfn\">Khai b\u00e1o c\u00e1c bi\u1ebfn<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Immediate_Window\" title=\"Immediate Window\">Immediate Window<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Dien_vao_giua_cac_bien_va_o\" title=\"\u0110i\u1ec1n v\u00e0o gi\u1eefa c\u00e1c bi\u1ebfn v\u00e0 \u00f4\">\u0110i\u1ec1n v\u00e0o gi\u1eefa c\u00e1c bi\u1ebfn v\u00e0 \u00f4<\/a><\/li>\n<li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/blog.hocexcel.online\/huong-dan-vba-co-ban-cho-nguoi-moi-bat-dau.html#Loi_khong_khop_Type_Mismatch\" title=\"L\u1ed7i kh\u00f4ng kh\u1edbp (Type Mismatch)\">L\u1ed7i kh\u00f4ng kh\u1edbp (Type Mismatch)<\/a><\/li>\n<\/ul>\n<\/nav>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Cac_thuat_ngu_co_ban_su_dung_trong_bai_viet\"><\/span><b>C\u00e1c thu\u1eadt ng\u1eef c\u01a1 b\u1ea3n s\u1eed d\u1ee5ng trong b\u00e0i vi\u1ebft\u00a0<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Macro Excel: chu\u1ed7i c\u00e1c l\u1ec7nh m\u00e0 b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng h\u00f3a c\u00e1c t\u00e1c v\u1ee5.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">VBA: l\u00e0 ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh s\u1eed d\u1ee5ng \u0111\u1ec3 t\u1ea1o macro. \u0110\u00e2y l\u00e0 vi\u1ebft t\u1eaft c\u1ee7a Visual Basic for Application.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Line of code (d\u00f2ng m\u00e3): \u0110\u00e2y l\u00e0 c\u00e1c l\u1ec7nh trong VBA.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">SUB: m\u1ed9t sub \u0111\u01b0\u1ee3c t\u1ea1o th\u00e0nh t\u1eeb nhi\u1ec1u line of code (d\u00f2ng m\u00e3). Khi sub ch\u1ea1y VBA s\u1ebd \u0111i qua c\u00e1c d\u00f2ng m\u00e3 v\u00e0 th\u1ef1c hi\u1ec7n c\u00e1c thao t\u00e1c th\u00edch h\u1ee3p. Macro v\u00e0 Sub v\u1ec1 c\u01a1 b\u1ea3n gi\u1ed1ng nhau.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Module: module ch\u1ec9 \u0111\u01a1n gi\u1ea3n l\u00e0 v\u00f9ng ch\u1ee9a c\u00e1c Sub. C\u00e1c sub ch\u1ee9a d\u00f2ng m\u00e3. Kh\u00f4ng c\u00f3 gi\u1edbi h\u1ea1n v\u1ec1 s\u1ed1 l\u01b0\u1ee3ng \u0111\u1ed1i v\u1edbi module trong workbook ho\u1eb7c s\u1ed1 l\u01b0\u1ee3ng sub trong m\u1ed9t module.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">VBA Editor: \u0110\u00e2y l\u00e0 v\u1ecb tr\u00ed vi\u1ebft m\u00e3. Nh\u1ea5n Alt+F11 s\u1ebd chuy\u1ec3n \u0111\u1ed5i gi\u1eefa Excel v\u00e0 Visual Basic Editor. N\u1ebfu Visual Basic kh\u00f4ng th\u00ec nh\u1ea5n Alt+F11 s\u1ebd t\u1ef1 \u0111\u1ed9ng m\u1edf.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">\u1ea2nh ch\u1ee5p m\u00e0n h\u00ecnh b\u00ean d\u01b0\u1edbi hi\u1ec3n th\u1ecb c\u00e1c ph\u1ea7n ch\u00ednh c\u1ee7a Visual Basic Editor:<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Thu_thuat_khi_hoat_dong_VBA\"><\/span><b>Th\u1ee7 thu\u1eadt khi ho\u1ea1t \u0111\u1ed9ng VBA<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Khi th\u1ef1c hi\u1ec7n c\u00e1c ho\u1ea1t \u0111\u1ed9ng trong b\u00e0i h\u01b0\u1edbng d\u1eabn n\u00e0y h\u00e3y \u0111\u00f3ng t\u1ea5t c\u1ea3 c\u00e1c workbook kh\u00e1c \u0111ang l\u00e0m vi\u1ec7c trong Excel.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Tao_module\"><\/span><b>T\u1ea1o module<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Trong excel ch\u00fang ta s\u1eed d\u1ee5ng ng\u00f4n ng\u1eef VBA \u0111\u1ec3 t\u1ea1o macro. VBA l\u00e0 vi\u1ebft t\u1eaft c\u1ee7a Visual Basic For Applications. Khi s\u1eed d\u1ee5ng thu\u1eadt ng\u1eef Excel Macro c\u00f3 ngh\u0129a l\u00e0 \u0111ang \u0111\u1ec1 c\u1eadp \u0111\u1ebfn VBA. Thu\u1eadt ng\u1eef macro v\u1ec1 c\u01a1 b\u1ea3n l\u00e0 m\u1ed9t t\u00ean g\u1ecdi kh\u00e1c c\u1ee7a sub.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Trong VBA ch\u00fang ta t\u1ea1o c\u00e1c d\u00f2ng ch\u1ec9 d\u1eabn \u0111\u1ec3 VBA x\u1eed l\u00fd. Ch\u00fang ta \u0111\u1eb7t c\u00e1c d\u00f2ng m\u00e3 trong m\u1ed9t sub. C\u00e1c sub n\u00e0y \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef trong m\u00f4-\u0111un.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Hoat_dong_1\"><\/span><b>Ho\u1ea1t \u0111\u1ed9ng 1:<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">M\u1edf m\u1ed9t workbook l\u00e0m vi\u1ec7c m\u1edbi trong Excel.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">M\u1edf Visual Basic(Alt+F11).<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Chuy\u1ec3n \u0111\u1ebfn c\u1eeda s\u1ed5 Project \u2013 VBAProject \u1edf b\u00ean tr\u00e1i (ho\u1eb7c nh\u1ea5n Ctrl+R).<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">B\u1ea5m chu\u1ed9t ph\u1ea3i v\u00e0o workbook v\u00e0 b\u1ea5m Insert, sau \u0111\u00f3 nh\u1ea5p v\u00e0o Module.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Nh\u1ea5p v\u00e0o Module 1 trong c\u1eeda s\u1ed5 Project- VBAProject.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Trong c\u1eeda s\u1ed5 Property \u1edf d\u01b0\u1edbi c\u00f9ng b\u00ean tr\u00e1i (F4 n\u1ebfu kh\u00f4ng hi\u1ec3n th\u1ecb) thay \u0111\u1ed5i t\u00ean module1 th\u00e0nh Myfirstmodule.<\/span><\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Ket_thuc_hoat_dong_1\"><\/span><b>K\u1ebft th\u00fac ho\u1ea1t \u0111\u1ed9ng 1<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400\">Module ch\u1ec9 \u0111\u01a1n gi\u1ea3n l\u00e0 n\u01a1i b\u1ea1n ch\u1ee9a m\u00e3. Module gi\u1ed1ng nh\u01b0 l\u00e0 c\u00e1c k\u1ec7 s\u00e1ch trong hi\u1ec7u s\u00e1ch. M\u1ee5c \u0111\u00edch ch\u00ednh l\u00e0 l\u01b0u tr\u1eef s\u00e1ch theo s\u1ef1 ph\u00e2n chia c\u1ee5 th\u1ec3 \u0111\u1ec3 t\u1ed5ng th\u1ec3 c\u00f3 t\u1ed5 ch\u1ee9c v\u00e0 c\u1ea5u tr\u00fac h\u01a1n.<\/span><\/p>\n<p><span style=\"font-weight: 400\">C\u1eeda s\u1ed5 ch\u00ednh hay l\u00e0 c\u1eeda s\u1ed5 m\u00e3 l\u00e0 v\u1ecb tr\u00ed \u0111\u1ec3 vi\u1ebft m\u00e3. \u0110\u1ec3 xem m\u00e3 cho b\u1ea5t k\u1ef3 module n\u00e0o b\u1ea1n ch\u1ec9 c\u1ea7n \u0111\u00fap v\u00e0o m\u1ee5c Project-VBAProject.<\/span><\/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\/2024\/12\/vba101_92019-nho-63.gif\" title=\"vba101_92019-nho-63\"><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\/2024\/12\/ex101_92019-nho-153.gif\" title=\"ex101_92019-nho-153\"><br \/>\n<\/a>\n<\/div>\n<\/div>\n<h3><span class=\"ez-toc-section\" id=\"Hoat_dong_2\"><\/span><b>Ho\u1ea1t \u0111\u1ed9ng 2<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">M\u1edf workbook m\u1edbi v\u00e0 t\u1ea1o m\u1ed9t module gi\u1ed1ng h\u1ec7t nh\u01b0 \u0111\u00e3 l\u00e0m trong ho\u1ea1t \u0111\u1ed9ng tr\u01b0\u1edbc.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">B\u1ea5m \u0111\u00fap v\u00e0o module m\u1edbi trong c\u1eeda s\u1ed5 Project-VBAProject.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">C\u1eeda s\u1ed5 m\u00e3 cho module n\u00e0y m\u1edf ra. B\u1ea1n th\u1ea5y t\u00ean thanh ti\u00eau \u0111\u1ec1 c\u1ee7a Visual Basic.<\/span><\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Ket_thuc_hoat_dong_2\"><\/span><b>K\u1ebft th\u00fac ho\u1ea1t \u0111\u1ed9ng 2<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400\">Vi\u1ec7c c\u00f3 bao nhi\u00eau module trong workbook v\u00e0 bao nhi\u00eau m\u1ee5c Sub trong m\u1ed9t module l\u00e0 t\u00f9y v\u00e0o m\u1ee5c \u0111\u00edch t\u00e1c v\u1ee5. Ngo\u00e0i ra c\u00e1ch \u0111\u1eb7t t\u00ean cho module v\u00e0 c\u00e1ch t\u1ed5 ch\u1ee9c c\u00e1c Sub c\u0169ng s\u1ebd t\u00f9y thu\u1ed9c v\u00e0o b\u1ea1n.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Trong ph\u1ea7n ti\u1ebfp theo s\u1ebd h\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng Sub.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cach_su_dung_Sub\"><\/span><b>C\u00e1ch s\u1eed d\u1ee5ng Sub<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">M\u1ed7i d\u00f2ng m\u00e3 l\u00e0 m\u1ed9t l\u1ec7nh \u0111\u1ec3 VBA x\u1eed l\u00fd. V\u00e0 c\u00e1c d\u00f2ng m\u00e3 \u0111\u00f3 \u0111\u01b0\u1ee3c nh\u00f3m l\u1ea1i g\u1ecdi l\u00e0 sub v\u00e0 \u0111\u1eb7t c\u00e1c sub n\u00e0y trong module.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ch\u00fang ta t\u1ea1o sub \u0111\u1ec3 VBA x\u1eed l\u00fd c\u00e1c l\u1ec7nh trong m\u1ed7i d\u00f2ng m\u00e3 m\u00e0 ch\u00fang ta \u0111\u01b0a ra. Khi ch\u00fang ta ch\u1ecdn <\/span><b>Run Sub<\/b><span style=\"font-weight: 400\"> t\u1eeb menu th\u00ec VBA s\u1ebd qu\u00e9t qua c\u00e1c d\u00f2ng m\u00e3 trong Sub v\u00e0 x\u1eed l\u00fd l\u1ea7n l\u01b0\u1ee3t.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Hoat_dong_3\"><\/span><b>Ho\u1ea1t \u0111\u1ed9ng 3<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">T\u1ea1o module nh\u01b0 h\u01b0\u1edbng d\u1eabn \u0111\u1ea7u ti\u00ean.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Ch\u1ecdn module m\u1edf c\u1eeda s\u1ed5 Project-VBAproject nh\u1ea5p v\u00e0o module c\u1ea7n ch\u1ecdn. \u0110\u1ea3m b\u1ea3o t\u00ean hi\u1ec3n th\u1ecb tr\u00ean thanh ti\u00eau \u0111\u1ec1.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Nh\u1eadp d\u00f2ng sau v\u00e0o c\u1eeda s\u1ed5 m\u00e3 v\u00e0 nh\u1ea5n Enter.<\/span><\/li>\n<\/ol>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">VBA s\u1ebd t\u1ef1 \u0111\u1ed9ng th\u00eam d\u00f2ng th\u1ee9 2 End Sub. Ch\u00fang ta \u0111\u1eb7t m\u00e3 gi\u1eefa hai d\u00f2n g n\u00e0y.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Gi\u1eefa 2 d\u00f2ng n\u00e0y nh\u1eadp d\u00f2ng<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">B\u1ea1n \u0111\u00e3 t\u1ea1o \u0111\u01b0\u1ee3c m\u1ed9t ph\u1ee5:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Nh\u1ea5p v\u00e0o sub \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o con tr\u1ecf \u0111\u01b0\u1ee3c \u0111\u1eb7t \u1edf \u0111\u00f3. Ch\u1ecdn RunRun Sub\/UserForm t\u1eeb menu\u00a0 (ho\u1eb7c nh\u1ea5n F5).<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">L\u01b0u \u00fd: n\u1ebfu b\u1ea1n kh\u00f4ng \u0111\u1eb7t con tr\u1ecf v\u00e0o sub VBA s\u1ebd ch\u1ea1y c\u00e1c tab \u0111ang hi\u1ec3n th\u1ecb.<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">M\u1edf Excel (Alt+F11). B\u1ea1n s\u1ebd th\u1ea5y gi\u00e1 tr\u1ecb 5 trong \u00f4 A1.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Th\u00eam t\u1eebng d\u00f2ng d\u01b0\u1edbi \u0111\u00e2y v\u00e0o sub, ch\u1ea1y sub v\u00e0 ki\u1ec3m tra k\u1ebft qu\u1ea3.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">B\u1ea1n s\u1ebd th\u1ea5y \u201csome text\u201d trong \u00f4 B1 ; 5,55 trong \u00f4 C3 \u0111\u1ebfn E5 v\u00e0 Now hi\u1ec3n th\u1ecb trong \u00f4 F1.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Ket_thuc_hoat_dong_3\"><\/span><b>K\u1ebft th\u00fac ho\u1ea1t \u0111\u1ed9ng 3.<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h2><span class=\"ez-toc-section\" id=\"Dien_gia_tri_vao_o\"><\/span><b>\u0110i\u1ec1n gi\u00e1 tr\u1ecb v\u00e0o \u00f4<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">H\u00e3y xem d\u00f2ng m\u00e3 trong ph\u1ea7n tr\u01b0\u1edbc<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ch\u00fang ta c\u0169ng c\u00f3 th\u1ec3 vi\u1ebft d\u00f2ng n\u00e0y nh\u01b0 th\u1ebf n\u00e0y<\/span><\/p>\n<p><span style=\"font-weight: 400\">Tuy nhi\u00ean b\u1ea1n kh\u00f4ng c\u1ea7n s\u1eed d\u1ee5ng Value v\u00ec \u0111\u00e2y l\u00e0 thu\u1ed9c t\u00ednh m\u1eb7c \u0111inh. Ch\u00fang ta s\u1eed d\u1ee5ng c\u00e1c d\u00f2ng m\u00e3 nh\u01b0 v\u1eady \u0111\u1ec3 g\u00e1n gi\u00e1 tr\u1ecb (v\u00ed d\u1ee5 nh\u01b0 sao ch\u00e9p) gi\u1eefa c\u00e1c \u00f4 v\u00e0 c\u00e1c bi\u1ebfn.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">VBA \u0111\u00e1nh gi\u00e1 b\u00ean ph\u1ea3i c\u1ee7a d\u1ea5u\u201d=\u201d v\u00e0 \u0111\u1eb7t k\u1ebft qu\u1ea3 v\u00e0o bi\u1ebfn \/cell\/ ph\u1ea1m vi n\u1eb1m b\u00ean tr\u00e1i d\u1ea7u b\u1eb1ng.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ph\u1ea7n m\u00e3 b\u00ean tr\u00e1i d\u1ea5u b\u1eb1ng<\/span><\/p>\n<p><span style=\"font-weight: 400\">Trong m\u00e3 n\u00e0y, Sheet 1 \u0111\u1ec1 c\u1eadp \u0111\u1ebfn t\u00ean m\u00e3 c\u1ee7a trang t\u00ednh. Ch\u00fang ta s\u1eed d\u1ee5ng t\u00ean m\u00e3 \u0111\u1ec3 tham chi\u1ebfu \u0111\u1ebfn c\u00e1c trang t\u00ednh trong workbook. Khi tham chi\u1ebfu \u0111\u1ebfn m\u1ed9t trang t\u00ednh th\u00ec ta c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng thu\u1ed9c t\u00ednh Range (Ph\u1ea1m vi) c\u1ee7a trang t\u00ednh \u0111\u1ec3 gi\u1edbi h\u1ea1n m\u1ed9t \u00f4 ho\u1eb7c nhi\u1ec1u \u00f4.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">B\u1eb1ng c\u00e1ch n\u00e0y ch\u00fang ta c\u00f3 th\u1ec3 sao ch\u00e9p gi\u00e1 tr\u1ecb t\u1eeb \u00f4 n\u00e0y sang \u00f4 kh\u00e1c.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">D\u01b0\u1edbi \u0111\u00e2y l\u00e0 v\u00ed d\u1ee5:<\/span><\/p>\n<p><b>Ho\u1ea1t \u0111\u1ed9ng 4<\/b><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">T\u1ea1o m\u1ed9t workbook m\u1edbi.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Th\u00eam c\u00e1c gi\u00e1 tr\u1ecb v\u00e0o c\u00e1c \u00f4 trong Sheet1 b\u1eb1ng c\u00e1ch th\u1ee7 c\u00f4ng nh\u01b0 sau: 20 v\u1edbi C1 v\u00e0 80 v\u1edbi C2.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">T\u1ea1o m\u1ed9t sub m\u1edbi c\u00f3 t\u00ean l\u00e0 Act4.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Vi\u1ebft m\u00e3 \u0111\u1ec3 \u0111\u1eb7t gi\u00e1 tr\u1ecb t\u1eeb C1 v\u00e0o A1.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Vi\u1ebft m\u00e3 \u0111\u1ec3 \u0111\u1eb7t k\u1ebft qu\u1ea3 c\u1ee7a C2+50 v\u00e0o \u00f4 A2.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Vi\u1ebft m\u00e3 \u0111\u1ec3 nh\u00e2n c\u00e1c gi\u00e1 tr\u1ecb trong \u00f4 C1 v\u00e0o C2. \u0110\u1eb7t k\u1ebft qu\u1ea3 v\u00e0o \u00f4 A3.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Ch\u1ea1y m\u00e3. C\u00e1c \u00f4 ph\u1ea3i c\u00f3 gi\u00e1 tr\u1ecb A1 20. A2 130 v\u00e0 A3 l\u00e0 1600.<\/span><\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Cac_o_trong_cac_trang_tinh_khac_nhau\"><\/span><b>C\u00e1c \u00f4 trong c\u00e1c trang t\u00ednh kh\u00e1c nhau<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Ch\u00fang ta c\u00f3 th\u1ec3 d\u1ec5 d\u00e0ng sao ch\u00e9p gi\u1eefa c\u00e1c \u00f4 tr\u00ean c\u00e1c trang t\u00ednh kh\u00e1c nhau. N\u00f3 c\u0169ng t\u01b0\u01a1ng t\u1ef1 v\u1edbi sao ch\u00e9p c\u00e1c \u00f4 tr\u00ean c\u00f9ng m\u1ed9t trang t\u00ednh. S\u1ef1 kh\u00e1c bi\u1ec7t duy nh\u1ea5t l\u00e0 t\u00ean trang t\u00ednh s\u1eed d\u1ee5ng trong m\u00e3.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Trong ho\u1ea1t \u0111\u1ed9ng d\u01b0\u1edbi \u0111\u00e2y s\u1ebd h\u01b0\u1edbng d\u1eabn ch\u00fang ta th\u1ef1c hi\u1ec7n.<\/span><\/p>\n<p><b><i>Ho\u1ea1t \u0111\u1ed9ng 5.<\/i><\/b><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Th\u00eam m\u1ed9t trang t\u00ednh m\u1edbi v\u00e0o workbook l\u00e0m vi\u1ec7c. B\u00e2y gi\u1edd c\u00f3 2 trang t\u00ednh l\u00e0 sheet1 v\u00e0 sheet 2.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">T\u1ea1o m\u1ed9t sub m\u1edbi c\u00f3 t\u00ean l\u00e0 Act5.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Th\u00eam m\u00e3 \u0111\u1ec3 sao ch\u00e9p gi\u00e1 tr\u1ecb t\u1eeb C1 tr\u00ean Sheet1 sang \u00f4 A1 tr\u00ean Sheet2 .<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Th\u00eam m\u00e3 \u0111\u1ec3 \u0111\u1eb7t k\u1ebft qu\u1ea3 t\u1eeb C1 + C2 tr\u00ean Sheet1 \u0111\u1ebfn \u00f4 A2 tr\u00ean Sheet2 .<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Th\u00eam m\u00e3 \u0111\u1ec3 \u0111\u1eb7t k\u1ebft qu\u1ea3 t\u1eeb C1 * C2 tr\u00ean Sheet1 \u0111\u1ebfn \u00f4 A3 tr\u00ean Sheet2 .<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Ch\u1ea1y m\u00e3 trong sub (F5). C\u00e1c \u00f4 tr\u00ean Sheet2 ph\u1ea3i c\u00f3 c\u00e1c gi\u00e1 tr\u1ecb nh\u01b0 sau: A1 20 , A2 100 v\u00e0 A3 1600<\/span><\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Ten_ma_cua_trang_tinh\"><\/span><b>T\u00ean m\u00e3 c\u1ee7a trang t\u00ednh<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">T\u1ea5t c\u1ea3 h\u01b0\u1edbng d\u1eabn tr\u00ean \u0111\u00e2y ch\u00fang ta s\u1eed d\u1ee5ng t\u00ean m\u1eb7c \u0111\u1ecbnh cho c\u00e1c trang t\u00ednh nh\u01b0 Sheet1 v\u00e0 Sheet 2. \u0110\u1ec3 \u0111\u1eb7t t\u00ean kh\u00e1c ch\u00fang ta thay \u0111\u1ed5i t\u00ean m\u00e3 c\u1ee7a trang t\u00ednh. Trong c\u1eeda s\u1ed5 Project-VBAProject b\u1ea1n s\u1ebd th\u1ea5y sheet1 c\u1ea3 b\u00ean trong v\u00e0 b\u00ean ngo\u00e0i d\u1ea5u ngo\u1eb7c \u0111\u01a1n.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><i><span style=\"font-weight: 400\">Sheet1<\/span><\/i><span style=\"font-weight: 400\">\u00a0b\u00ean tr\u00e1i l\u00e0 t\u00ean m\u00e3 c\u1ee7a trang t\u00ednh.<\/span><\/li>\n<li style=\"font-weight: 400\"><i><span style=\"font-weight: 400\">Sheet1<\/span><\/i><span style=\"font-weight: 400\">\u00a0b\u00ean ph\u1ea3i (trong ngo\u1eb7c \u0111\u01a1n) l\u00e0 t\u00ean trang t\u00ednh.\u00a0\u0110\u00e2y l\u00e0 t\u00ean b\u1ea1n th\u1ea5y tr\u00ean tab trong Excel.<\/span><\/li>\n<\/ul>\n<p><b><i>T\u00ean m\u00e3 c\u00f3 c\u00e1c thu\u1ed9c t\u00ednh sau:<\/i><\/b><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">C\u00f3 th\u1ec3 s\u1eed d\u1ee5ng n\u00f3 tham chi\u1ebfu tr\u1ef1c ti\u1ebfp trang t\u00ednh nh\u01b0 \u0111\u00e3 l\u00e0m. V\u00ed d\u1ee5:<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">L\u01b0u \u00fd: ch\u00fang ta ch\u1ec9 c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng t\u00ean m\u00e3 n\u1ebfu trang t\u00ednh n\u1eb1m trong c\u0169ng workbook v\u1edbi m\u00e3.<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">N\u1ebfu t\u00ean trang t\u00ednh thay \u0111\u1ed5i m\u00e3 s\u1ebd v\u1eabn ho\u1ea1t \u0111\u1ed9ng n\u1ebfu ch\u00fang ta s\u1eed d\u1ee5ng t\u00ean m\u00e3 \u0111\u1ec3 tham chi\u1ebfu \u0111\u1ebfn trang t\u00ednh.<\/span><\/li>\n<\/ol>\n<p><b><i>T\u00ean trang t\u00ednh c\u00f3 c\u00e1c thu\u1ed9c t\u00ednh sau:<\/i><\/b><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\u0110\u1ec3 tham chi\u1ebfu trang t\u00ednh b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng t\u00ean trang t\u00ednh, ch\u00fang ta c\u1ea7n s\u1eed d\u1ee5ng c\u1ea3 workbook v\u00ed d\u1ee5 nh\u01b0 sau<\/span><\/li>\n<\/ol>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">N\u1ebfu t\u00ean trang t\u00ednh thay \u0111\u1ed5i ch\u00fang ta ph\u1ea3i thay \u0111\u1ed5i t\u00ean trong m\u00e3 c\u1ee7a m\u00ecnh. V\u00ed d\u1ee5: n\u1ebfu thay \u0111\u1ed5i t\u00ean sheet1 th\u00e0nh Data th\u00ec cgungs ta c\u1ea7n thay nh\u01b0 sau:<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">Ch\u00fang ta ch\u1ec9 c\u00f3 th\u1ec3 thay \u0111\u1ed5i t\u00ean m\u00e3 trong c\u1eeda s\u1ed5 Property.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ch\u00fang ta c\u00f3 th\u1ec3 thay \u0111\u1ed5i t\u00ean trang t\u00ednh t\u1eeb tab v\u00e0 c\u1ea3 c\u1eeda s\u1ed5 Property.<\/span><\/p>\n<p><b><i>Ho\u1ea1t \u0111\u1ed9ng 6:\u00a0<\/i><\/b><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">M\u1edf m\u1ed9t workbook l\u00e0m vi\u1ec7c m\u1edbi v\u00e0 t\u1edbi Visual Basic.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Nh\u1ea5p v\u00e0o Sheet1 trong C\u1eeda s\u1ed5 Project \u2013 VBAProject (Ctrl + R n\u1ebfu kh\u00f4ng hi\u1ec3n th\u1ecb).<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Chuy\u1ec3n \u0111\u1ebfn c\u1eeda s\u1ed5 Thu\u1ed9c t\u00ednh (F4 n\u1ebfu kh\u00f4ng hi\u1ec3n th\u1ecb).<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Thay \u0111\u1ed5i t\u00ean m\u00e3 c\u1ee7a trang t\u00ednh th\u00e0nh shReport .<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">T\u1ea1o m\u1ed9t module m\u1edbi \u0111\u1eb7t t\u00ean modAct6. .<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Th\u00eam sub sau v\u00e0 ch\u1ea1y (F5)<\/span><\/li>\n<\/ol>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Sau \u0111\u00f3 th\u00eam sub v\u00e0 ch\u1ea1y<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\u00d4 A1 b\u00e2y gi\u1edd ph\u1ea3i c\u00f3 gi\u00e1 tr\u1ecb\u00a0<\/span><i><span style=\"font-weight: 400\">66<\/span><\/i><span style=\"font-weight: 400\">\u00a0v\u00e0 \u00f4 B2 ph\u1ea3i c\u00f3 gi\u00e1 tr\u1ecb\u00a0<\/span><i><span style=\"font-weight: 400\">55<\/span><\/i><span style=\"font-weight: 400\">\u00a0.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Thay \u0111\u1ed5i t\u00ean c\u1ee7a trang t\u00ednh trong Excel th\u00e0nh\u00a0<\/span><i><span style=\"font-weight: 400\">report<\/span><\/i><span style=\"font-weight: 400\">\u00a0 b\u1eb1ng c\u00e1ch nh\u1ea5p chu\u1ed9t ph\u1ea3i v\u00e0o tab trang t\u00ednh v\u00e0 \u0111\u1ed5i t\u00ean.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">X\u00f3a n\u1ed9i dung c\u1ee7a c\u00e1c \u00f4 v\u00e0 ch\u1ea1y\u00a0l\u1ea1i m\u00e3\u00a0<\/span><i><span style=\"font-weight: 400\">UseCodename<\/span><\/i><span style=\"font-weight: 400\">.\u00a0M\u00e3 s\u1ebd v\u1eabn ch\u1ea1y ch\u00ednh x\u00e1c.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Ch\u1ea1y l\u1ea1i\u00a0<\/span><i><span style=\"font-weight: 400\">sub<\/span><\/i><span style=\"font-weight: 400\">\u00a0<\/span><i><span style=\"font-weight: 400\">UseWorksheetname<\/span><\/i><span style=\"font-weight: 400\">\u00a0.\u00a0B\u1ea1n s\u1ebd g\u1eb7p l\u1ed7i\u00a0<\/span><i><span style=\"font-weight: 400\">\u201cSubscript out of Range\u201d<\/span><\/i><span style=\"font-weight: 400\">\u00a0 c\u00f3 ngh\u0129a l\u00e0 kh\u00f4ng c\u00f3 trang t\u00ednh n\u00e0o \u0111\u01b0\u1ee3c g\u1ecdi l\u00e0\u00a0<\/span><b>Sheet1<\/b><span style=\"font-weight: 400\">\u00a0trong b\u1ed9 s\u01b0u t\u1eadp trang t\u00ednh.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Thay \u0111\u1ed5i m\u00e3 nh\u01b0 sau v\u00e0 ch\u1ea1y l\u1ea1i.\u00a0B\u00e2y gi\u1edd m\u00e3 s\u1ebd ch\u1ea1y ch\u00ednh x\u00e1c.<\/span><\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Lenh_With\"><\/span><b>L\u1ec7nh With<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">C\u00f3 m\u1ed9t \u0111i\u1ec1u d\u1ec5 nh\u1eadn th\u1ea5y \u0111\u00f3 l\u00e0 ch\u00fang ta c\u1ea7n s\u1eed d\u1ee5ng t\u00ean trang t\u00ednh nhi\u1ec1u m\u1ed7i khi mu\u1ed1n tham chi\u1ebfu ph\u1ea1m vi trong m\u00e3. M\u1ed9t c\u00e1ch \u0111\u01a1n gi\u1ea3n h\u01a1n l\u00e0 ch\u00fang ta s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh With.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0Ch\u00fang ta ch\u1ec9 c\u1ea7n \u0111\u1ec1 c\u1eadp t\u00ean trang t\u00ednh m\u1ed9t l\u1ea7n v\u00e0 VBA s\u1ebd \u00e1p d\u1ee5ng cho b\u1ea5t k\u1ef3 ph\u1ea1m vi n\u00e0o ch\u00fang ta s\u1eed d\u1ee5ng.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Trong VBA ch\u00fang ta l\u1ea5y b\u1ea5t k\u1ef3 m\u1ee5c n\u00e0o tr\u01b0\u1edbc khi d\u1eebng m\u00e3 v\u00e0 s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh With.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">C\u1eadp nh\u1eadt v\u1edbi c\u00e2u l\u1ec7nh With<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ch\u00fang ta s\u1eed d\u1ee5ng With \u0111\u1ec3 b\u1eaft \u0111\u1ea7u trong v\u00ed d\u1ee5 tr\u00ean. B\u1ea5t c\u1ee9 khi n\u00e0o VBA d\u1eebng ho\u00e0n to\u00e0n n\u00f3 s\u1ebd s\u1eed d\u1ee5ng trang t\u00ednh tr\u01b0\u1edbc \u0111\u00f3.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ch\u00fang ta s\u1eed d\u1ee5ng l\u1ec7nh With v\u1edbi c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng trong VBA bao g\u1ed3m workbook, range, bi\u1ec3u \u0111\u1ed3\u2026<\/span><\/p>\n<p><span style=\"font-weight: 400\">Bi\u1ec3u th\u1ecb k\u1ebft th\u00fac l\u1ec7nh with b\u1eb1ng Endwith.\u00a0<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Thut_le_voi_cac_dong_ma\"><\/span><b>Th\u1ee5t l\u1ec1 v\u1edbi c\u00e1c d\u00f2ng m\u00e3<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">B\u1ea1n ch\u00fa \u00fd l\u00e0 c\u00e1c d\u00f2ng d\u00f2ng m\u00e3 gi\u1eefa \u1edf gi\u1eefa \u0111\u1ec1u th\u1ee5t sang ph\u1ea3i. \u0110i\u1ec1u n\u00e0y g\u1ecdi l\u00e0 th\u1ee5t l\u1ec1 m\u00e3.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ch\u00fang ta lu\u00f4n lu\u00f4n th\u1ee5t l\u1ec1 m\u00e3 gi\u1eefa c\u00e1c m\u1ee5c trong VBA nh\u01b0 Sub, c\u00e2u l\u1ec7nh IF, with For loop\u2026<\/span><\/p>\n<p><span style=\"font-weight: 400\">B\u1ea1n c\u00f3 th\u1ec3 s\u1eafp x\u1ebfp c\u00e1c d\u00f2ng m\u00e3 \u1edf b\u00ean ph\u1ea3i b\u1eb1ng c\u00e1ch ch\u1ecdn c\u00e1c d\u00f2ng m\u00e3 th\u00edch h\u1ee3p v\u00e0 nh\u1ea5n ph\u00edm Tab. Nh\u1ea5n Shift v\u00e0 Tab s\u1ebd chuy\u1ec3n sang tr\u00e1i.<\/span><\/p>\n<p><b><i>Ho\u1ea1t \u0111\u1ed9ng 7<\/i><\/b><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Vi\u1ebft l\u1ea1i \u0111o\u1ea1n m\u00e3 sau b\u1eb1ng c\u00e2u l\u1ec7nh With<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">L\u1eddi gi\u1ea3i:<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Sao_chep_gia_tri_giua_nhieu_o\"><\/span><b>Sao ch\u00e9p gi\u00e1 tr\u1ecb gi\u1eefa nhi\u1ec1u \u00f4<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">B\u1ea1n c\u00f3 th\u1ec3 sao ch\u00e9p c\u00e1c gi\u00e1 tr\u1ecb t\u1eeb d\u1ea3i \u00f4 n\u00e0y sang d\u1ea3i \u00f4 kh\u00e1c<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u0110i\u1ec1u c\u1ea7n l\u01b0u \u00fd l\u00e0 ch\u00fang ta s\u1eed d\u1ee5ng thu\u1ed9c t\u00ednh Value c\u1ee7a v\u00f9ng d\u1eef li\u1ec7u ngu\u1ed3n. N\u1ebfu b\u1ecf qua n\u00f3 \u0111\u1ec3 tr\u1ed1ng v\u00e0o v\u00f9ng d\u1eef li\u1ec7u \u0111\u00edch .<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u0110o\u1ea1n m\u00e3 tr\u00ean l\u00e0 m\u1ed9t c\u00e1ch r\u1ea5t hi\u1ec7u qu\u1ea3 \u0111\u1ec3 sao ch\u00e9p gi\u00e1 tr\u1ecb gi\u1eefa c\u00e1c \u00f4. B\u1ea1n kh\u00f4ng c\u1ea7n ph\u1ea3i ch\u1ecdn, sao ch\u00e9p v\u00e0 d\u00e1n m\u1ed9t c\u00e1ch th\u1ee7 c\u00f4ng.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Khi thao t\u00e1c n\u00ean nh\u1edb\u00a0 v\u00f9ng d\u1eef li\u1ec7u ngu\u1ed3n v\u00e0 d\u1eef li\u1ec7u \u0111\u00edch ph\u1ea3i c\u00f3 c\u00f9ng k\u00edch th\u01b0\u1edbc.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">N\u1ebfu v\u00f9ng d\u1eef li\u1ec7u \u0111\u00edch nh\u1ecf th\u00ec ch\u1ec9 \u00f4 trong ph\u1ea1m b\u1ecb m\u1edbi \u0111\u01b0\u1ee3c l\u1ea5p \u0111\u1ea7y. \u0110i\u1ec1u n\u00e0y kh\u00e1c v\u1edbi Copy\/Paste \u1edf ch\u1ed7 ch\u00fang ta ch\u1ec9 c\u1ea7n ch\u1ec9 \u0111\u1ecbnh \u00f4 \u0111\u1ea7u ti\u00ean v\u00e0 Excel s\u1ebd \u0111i\u1ec1n c\u00e1c \u00f4 c\u00f2n l\u1ea1i.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">N\u1ebfu v\u00f9ng d\u1eef li\u1ec7u \u0111\u00edch l\u1edbn h\u01a1n th\u00ec c\u00e1c \u00f4 b\u1ecb d\u01b0 s\u1ebd hi\u1ec3n th\u1ecb #N.A.<\/span><\/li>\n<\/ul>\n<p><b><i>Ho\u1ea1t \u0111\u1ed9ng 8:<\/i><\/b><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">T\u1ea1o m\u1ed9t workbook.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Th\u00eam m\u1ed9t trang t\u00ednh m\u1edbi v\u00e0o workbook bao g\u1ed3m sheet 1 v\u00e0 sheet 2.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Th\u00eam d\u1eef li\u1ec7u sau v\u00e0o v\u00f9ng d\u1eef li\u1ec7u C2:E4 tr\u00ean sheet1.<\/span><\/li>\n<\/ol>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Vi\u1ebft m\u00e3 \u0111\u1ec3 sao ch\u00e9p d\u1eef li\u1ec7u t\u1eeb Sheet1 sang ph\u1ea1m vi B3: D5 tr\u00ean Sheet2.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Ch\u1ea1y m\u00e3 (F5).<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">X\u00f3a k\u1ebft qu\u1ea3 v\u00e0 sau \u0111\u00f3 thay \u0111\u1ed5i ph\u1ea1m vi \u0111\u00edch nh\u1ecf h\u01a1n ph\u1ea1m vi ngu\u1ed3n.\u00a0Ch\u1ea1y l\u1ea1i v\u00e0 ki\u1ec3m tra k\u1ebft qu\u1ea3.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">X\u00f3a k\u1ebft qu\u1ea3 v\u00e0 sau \u0111\u00f3 thay \u0111\u1ed5i ph\u1ea1m vi \u0111\u00edch l\u1edbn h\u01a1n ph\u1ea1m vi ngu\u1ed3n.\u00a0Ch\u1ea1y l\u1ea1i v\u00e0 ki\u1ec3m tra k\u1ebft qu\u1ea3.<\/span><\/li>\n<\/ol>\n<p><b><i>L\u1eddi gi\u1ea3i<\/i><\/b><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Chuyen_doi_vung_du_lieu_o\"><\/span><b>Chuy\u1ec3n \u0111\u1ed5i v\u00f9ng d\u1eef li\u1ec7u \u00f4<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">N\u1ebfu b\u1ea1n c\u1ea7n chuy\u1ec3n \u0111\u1ed5i t\u1eeb h\u00e0ng sang c\u1ed9t v\u00e0 ng\u01b0\u1ee3c l\u1ea1i c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng WorksheetFunction Transpose. \u0110\u1eb7t c\u00e1c gi\u00e1 tr\u1ecb t\u1eeb 1 \u0111\u1ebfn 4 v\u00e0o c\u00e1c \u00f4 A1 \u0111\u1ebfn A4.\u00a0\u0110o\u1ea1n m\u00e3 sau s\u1ebd ghi c\u00e1c gi\u00e1 tr\u1ecb t\u1eeb E1 \u0111\u1ebfn H1<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u0110o\u1ea1n m\u00e3 sau s\u1ebd \u0111\u1ecdc t\u1eeb E1: H1 \u0111\u1ebfn L1: L4<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ch\u00fang ta c\u00f3 th\u1ec3 chia m\u1ed9t d\u00f2ng tr\u00ean nhi\u1ec1u d\u00f2ng b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng d\u1ea5u g\u1ea1ch d\u01b0\u1edbi (_), v\u00ed d\u1ee5:<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cach_su_dung_cac_bien\"><\/span><b>C\u00e1ch s\u1eed d\u1ee5ng c\u00e1c bi\u1ebfn<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Bi\u1ebfn l\u00e0 m\u1ed9t ph\u1ea7n trong ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh. C\u00e1c bi\u1ebfn gi\u1ed1ng nh\u01b0 c\u00e1c \u00f4 nh\u1ecf trong b\u1ed9 nh\u1edb. Ch\u00fang ta s\u1eed d\u1ee5ng \u0111\u1ec3 l\u01b0u c\u00e1c gi\u00e1 tr\u1ecb t\u1ea1m th\u1eddi trong khi m\u00e3 \u0111ang ch\u1ea1y.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ch\u00fang ta th\u1ef1c hi\u1ec7n v\u1edbi bi\u1ebfn nh\u01b0 sau:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Khai b\u00e1o (t\u1ee9c l\u00e0 t\u1ea1o bi\u1ebfn).<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">L\u01b0u tr\u1eef m\u1ed9t gi\u00e1 tr\u1ecb trong bi\u1ebfn.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\u0110\u1ecdc m\u1ed9t gi\u00e1 tr\u1ecb l\u01b0u tr\u1eef trong bi\u1ebfn.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">C\u00e1c ki\u1ec3u bi\u1ebfn ch\u00fang ta s\u1eed d\u1ee5ng c\u0169ng t\u01b0\u01a1ng t\u1ef1 c\u00e1c ki\u1ec3u d\u1eef li\u1ec7u ch\u00fang ta s\u1eed d\u1ee5ng trong Excel.<\/span><\/p>\n<p><span style=\"font-weight: 400\">B\u1ea3ng d\u01b0\u1edbi \u0111\u00e2y cho th\u1ea5y c\u00e1c bi\u1ebfn ph\u1ed5 bi\u1ebfn.\u00a0.\u00a0Tr\u00ean th\u1ef1c t\u1ebf, b\u1ea1n c\u00f3 th\u1ec3 s\u1ebd s\u1eed d\u1ee5ng Long v\u00e0 String cho 90% c\u00e1c bi\u1ebfn c\u1ee7a m\u00ecnh.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Type<\/b><\/td>\n<td><b>Chi ti\u1ebft<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Boolean<\/span><\/td>\n<td><span style=\"font-weight: 400\">Ch\u1ec9 c\u00f3 th\u1ec3 \u0111\u00fang ho\u1eb7c sai<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Currency<\/span><\/td>\n<td><span style=\"font-weight: 400\">Gi\u1ed1ng nh\u01b0 s\u1ed1 th\u1eadp ph\u00e2n nh\u01b0ng ch\u1ec9 c\u00f3 4 s\u1ed1 th\u1eadp ph\u00e2n<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Date<\/span><\/td>\n<td><span style=\"font-weight: 400\">S\u1eed d\u1ee5ng cho ng\u00e0y\/gi\u1edd<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Double<\/span><\/td>\n<td><span style=\"font-weight: 400\">S\u1eed d\u1ee5ng cho s\u1ed1 th\u1eadp ph\u00e2n<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Long<\/span><\/td>\n<td><span style=\"font-weight: 400\">S\u1eed d\u1ee5ng cho s\u1ed1 nguy\u00ean<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">String<\/span><\/td>\n<td><span style=\"font-weight: 400\">S\u1eed d\u1ee5ng cho v\u0103n b\u1ea3n<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Variant<\/span><\/td>\n<td><span style=\"font-weight: 400\">VBA s\u1ebd quy\u1ebft \u0111\u1ecbnh lo\u1ea1i bi\u1ebfn trong th\u1eddi gian ch\u1ea1y<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span class=\"ez-toc-section\" id=\"Khai_bao_cac_bien\"><\/span><b>Khai b\u00e1o c\u00e1c bi\u1ebfn<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">VBA kh\u00f4ng b\u1eaft bu\u1ed9c khai b\u00e1o bi\u1ebfn tuy nhi\u00ean ch\u00fang ta n\u00ean th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y \u0111\u1ec3 c\u00e1c thao t\u00e1c sau s\u1ebd d\u1ec5 d\u00e0ng h\u01a1n. \u0110\u1ec3 \u201cRequire Variable Declaration\u201d (y\u00eau c\u1ea7u khai b\u00e1o bi\u1ebfn) ch\u00fang ta th\u00eam d\u00f2ng sau v\u00e0o module:<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u0110\u1ec3 VBA t\u1ef1 \u0111\u1ed9ng th\u00eam d\u00f2ng n\u00e0y, h\u00e3y ch\u1ecdn Tools<\/span><i><span style=\"font-weight: 400\">-&gt; Options <\/span><\/i><span style=\"font-weight: 400\">\u00a0t\u1eeb menu v\u00e0 ch\u1ecdn\u00a0<\/span><i><span style=\"font-weight: 400\">Require Variable Declaration<\/span><\/i><span style=\"font-weight: 400\">\u00a0.\u00a0B\u1ea5t c\u1ee9 khi n\u00e0o b\u1ea1n t\u1ea1o m\u1ed9t module\u00a0 m\u1edbi, VBA s\u1ebd th\u00eam d\u00f2ng n\u00e0y v\u00e0o \u0111\u1ea7u.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Khai b\u00e1o m\u1ed9t bi\u1ebfn r\u1ea5t \u0111\u01a1n gi\u1ea3n, ch\u1ec9 c\u1ea7n s\u1eed d\u1ee5ng \u0111\u1ecbnh d\u1ea1ng sau:<\/span><\/p>\n<p><span style=\"font-weight: 400\">B\u1ea1n c\u00f3 th\u1ec3 t\u00f9y \u00fd \u0111\u1eb7t t\u00ean bi\u1ebfn. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 v\u00ed d\u1ee5 v\u1ec1 khai b\u00e1o:<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u0110\u1ec3 \u0111\u1eb7t gi\u00e1 tr\u1ecb trong m\u1ed9t bi\u1ebfn, ch\u00fang ta s\u1eed d\u1ee5ng c\u00f9ng ki\u1ec3u c\u00e2u l\u1ec7nh c\u00f3 d\u1ea5u b\u1eb1ng.<\/span><\/p>\n<p><b><i>Ho\u1ea1t \u0111\u1ed9ng 9:<\/i><\/b><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">T\u1ea1o m\u1ed9t sub m\u1edbi v\u00e0 \u0111\u1eb7t t\u00ean l\u00e0\u00a0<\/span><b>usingVariables<\/b><span style=\"font-weight: 400\">\u00a0.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Khai b\u00e1o m\u1ed9t bi\u1ebfn \u0111\u1ec3 l\u01b0u s\u1ed1 \u0111\u1ebfm v\u00e0 \u0111\u1eb7t gi\u00e1 tr\u1ecb l\u00e0\u00a0<\/span><i><span style=\"font-weight: 400\">5<\/span><\/i><span style=\"font-weight: 400\">\u00a0.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Khai b\u00e1o m\u1ed9t bi\u1ebfn \u0111\u1ec3 l\u01b0u gi\u00e1 v\u00e9 (price) v\u00e0 \u0111\u1eb7t gi\u00e1 tr\u1ecb l\u00e0\u00a0<\/span><i><span style=\"font-weight: 400\">99,99<\/span><\/i><span style=\"font-weight: 400\">\u00a0.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Khai b\u00e1o m\u1ed9t bi\u1ebfn \u0111\u1ec3 l\u01b0u tr\u1eef m\u1ed9t qu\u1ed1c gia v\u00e0 \u0111\u1eb7t gi\u00e1 tr\u1ecb th\u00e0nh\u00a0<\/span><i><span style=\"font-weight: 400\">\u201cSpain\u201d<\/span><\/i><span style=\"font-weight: 400\">\u00a0.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Khai b\u00e1o m\u1ed9t bi\u1ebfn \u0111\u1ec3 l\u01b0u tr\u1eef ng\u00e0y k\u1ebft th\u00fac v\u00e0 \u0111\u1eb7t gi\u00e1 tr\u1ecb l\u00e0\u00a0<\/span><i><span style=\"font-weight: 400\">ng\u00e0y 21st March 2020.<\/span><\/i><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Khai b\u00e1o m\u1ed9t bi\u1ebfn \u0111\u1ec3 l\u01b0u tr\u1eef n\u1ebfu m\u1ed9t c\u00e1i g\u00ec \u0111\u00f3 \u0111\u01b0\u1ee3c ho\u00e0n th\u00e0nh.\u00a0\u0110\u1eb7t gi\u00e1 tr\u1ecb th\u00e0nh\u00a0<\/span><i><span style=\"font-weight: 400\">Wrong<\/span><\/i><span style=\"font-weight: 400\">.<\/span><\/li>\n<\/ol>\n<p><b><i>L\u1eddi gi\u1ea3i:<\/i><\/b><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Immediate_Window\"><\/span><b>Immediate Window<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">VBA c\u00f3 m\u1ed9t c\u00f4ng c\u1ee5 ti\u1ec7n l\u1ee3i th\u1ef1c s\u1ef1 cho ph\u00e9p ch\u00fang t\u00f4i ki\u1ec3m tra \u0111\u1ea7u ra C\u00f4ng c\u1ee5 n\u00e0y l\u00e0 Immediate window.\u00a0B\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng\u00a0<\/span><b>Debug.Print,<\/b><span style=\"font-weight: 400\">\u00a0ch\u00fang ta c\u00f3 th\u1ec3 ghi c\u00e1c gi\u00e1 tr\u1ecb, v\u0103n b\u1ea3n v\u00e0 k\u1ebft qu\u1ea3 c\u1ee7a c\u00e1c ph\u00e9p t\u00ednh v\u00e0o immediate window.<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u0110\u1ec3 xem c\u1eeda s\u1ed5 n\u00e0y, b\u1ea1n c\u00f3 th\u1ec3 ch\u1ecdn\u00a0<\/span><i><span style=\"font-weight: 400\">View-&gt; Immediate window<\/span><\/i><span style=\"font-weight: 400\">\u00a0t\u1eeb menu ho\u1eb7c nh\u1ea5n Ctrl + G. C\u00e1c gi\u00e1 tr\u1ecb s\u1ebd \u0111\u01b0\u1ee3c ghi ngay c\u1ea3 khi Immediate window kh\u00f4ng hi\u1ec3n th\u1ecb.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ch\u00fang ta c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng Immediate window \u0111\u1ec3 vi\u1ebft ra c\u00e1c bi\u1ebfn \u0111\u1ec3 ki\u1ec3m tra c\u00e1c gi\u00e1 tr\u1ecb n\u00f3 ch\u1ee9a. N\u1ebfu c\u1eadp nh\u1eadt m\u00e3 t\u1eeb ho\u1ea1t \u0111\u1ed9ng cu\u1ed1i c\u00f9ng, ch\u00fang ta c\u00f3 th\u1ec3 ghi ra c\u00e1c gi\u00e1 tr\u1ecb c\u1ee7a m\u1ed7i bi\u1ebfn.\u00a0Ch\u1ea1y m\u00e3 b\u00ean d\u01b0\u1edbi v\u00e0 ki\u1ec3m tra k\u1ebft qu\u1ea3 trong Immediate window.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Dien_vao_giua_cac_bien_va_o\"><\/span><b>\u0110i\u1ec1n v\u00e0o gi\u1eefa c\u00e1c bi\u1ebfn v\u00e0 \u00f4<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Ch\u00fang ta c\u00f3 th\u1ec3 ghi v\u00e0 \u0111\u1ecdc gi\u00e1 tr\u1ecb gi\u1eefa \u00f4 v\u00e0 \u00f4, \u00f4 v\u00e0 bi\u1ebfn,\u00a0 bi\u1ebfn v\u00e0 bi\u1ebfn b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng d\u00f2ng g\u00e1n .<\/span><\/p>\n<p><span style=\"font-weight: 400\">V\u00ed d\u1ee5:<\/span><\/p>\n<p><b><i>Ho\u1ea1t \u0111\u1ed9ng 10:<\/i><\/b><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">T\u1ea1o m\u1ed9t workbook tr\u1ed1ng v\u1edbi c\u00f3 hai trang t\u00ednh: Sheet1 v\u00e0 Sheet2.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\u0110\u1eb7t v\u0103n b\u1ea3n \u201cNew York\u201d v\u00e0o \u00f4 A1 tr\u00ean sheet1.\u00a0\u0110\u1eb7t s\u1ed1 49 v\u00e0o \u00f4 C1 tr\u00ean Sheet2.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">T\u1ea1o sub \u0111\u1ecdc c\u00e1c gi\u00e1 tr\u1ecb th\u00e0nh c\u00e1c bi\u1ebfn t\u1eeb c\u00e1c \u00f4 n\u00e0y.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Th\u00eam m\u00e3 \u0111\u1ec3 ghi c\u00e1c gi\u00e1 tr\u1ecb v\u00e0o Immediate window.<\/span><\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Loi_khong_khop_Type_Mismatch\"><\/span><b>L\u1ed7i kh\u00f4ng kh\u1edbp (Type Mismatch)<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400\">VBA c\u00f3 th\u1ec3 chuy\u1ec3n \u0111\u1ed5i bi\u1ebfn. N\u1ebfu ch\u00fang ta g\u00e1n 99,55 cho bi\u1ebfn Long th\u00ec VBA s\u1ebd chuy\u1ec3n th\u00e0nh s\u1ed1 nguy\u00ean. V\u00ed d\u1ee5 trong \u0111o\u1ea1n m\u00e3 d\u01b0\u1edbi \u0111\u00e2y s\u1ebd l\u00e0m tr\u00f2n th\u00e0nh 100.<\/span><\/p>\n<p><span style=\"font-weight: 400\">VBA c\u00f3 th\u1ec3 chuy\u1ec3n \u0111\u1ed5i kh\u00e1 nhi\u1ec1u s\u1ed1 nh\u01b0 sau:<\/span><\/p>\n<p><span style=\"font-weight: 400\">Tuy nhi\u00ean, ngay c\u1ea3 VBA c\u0169ng c\u00f3 gi\u1edbi h\u1ea1n c\u1ee7a n\u00f3.\u00a0\u0110o\u1ea1n m\u00e3 sau s\u1ebd d\u1eabn \u0111\u1ebfn\u00a0l\u1ed7i\u00a0<\/span><b>Lo\u1ea1i kh\u00f4ng kh\u1edbp<\/b><span style=\"font-weight: 400\">\u00a0v\u00ec VBA kh\u00f4ng th\u1ec3 chuy\u1ec3n \u0111\u1ed5i v\u0103n b\u1ea3n th\u00e0nh s\u1ed1<\/span><\/p>\n<p><span style=\"font-weight: 400\">M\u1eb9o: C\u00e1c l\u1ed7i kh\u00f4ng kh\u1edbp th\u01b0\u1eddng x\u1ea3y ra do ng\u01b0\u1eddi d\u00f9ng v\u00f4 t\u00ecnh\u00a0 \u0111\u1eb7t v\u0103n b\u1ea3n v\u00e0o m\u1ed9t \u00f4 m\u00e0 ch\u1ee9a d\u1eef li\u1ec7u s\u1ed1.<\/span><\/p>\n<p><b><i>Ho\u1ea1t \u0111\u1ed9ng 11:<\/i><\/b><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Khai b\u00e1o\u00a0ki\u1ec3u bi\u1ebfn\u00a0<\/span><i><span style=\"font-weight: 400\">Double<\/span><\/i><span style=\"font-weight: 400\">\u00a0g\u1ecdi l\u00e0\u00a0<\/span><i><span style=\"font-weight: 400\">Amount.<\/span><\/i><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">G\u00e1n m\u1ed9t gi\u00e1 tr\u1ecb g\u00e2y ra l\u1ed7i Lo\u1ea1i Kh\u00f4ng kh\u1edbp (Mismatch type).<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Ch\u1ea1y m\u00e3 v\u00e0 \u0111\u1ea3m b\u1ea3o l\u1ed7i x\u1ea3y ra.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">Chu\u1ed7i n\u1ed9i dung trong Power Query<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400\"><a href=\"http:\/\/blog.ezworkapp.com\/tim-hieu-ve-power-query.html\"><strong>Gi\u1edbi thi\u1ec7u<\/strong><\/a><\/li>\n<li style=\"font-weight: 400\"><a href=\"http:\/\/blog.ezworkapp.com\/huong-dan-cach-dua-du-lieu-ve-dang-chuan-voi-power-query-trong-excel.html\"><strong>Nh\u1eadp d\u1eef li\u1ec7u<\/strong><\/a><\/li>\n<li style=\"font-weight: 400\"><a href=\"http:\/\/blog.ezworkapp.com\/power-query-la-gi-tai-sao-can-hoc-power-query.html\"><strong>L\u00e0m m\u1edbi d\u1eef li\u1ec7u Power Query<\/strong><\/a><\/li>\n<li style=\"font-weight: 400\"><a href=\"http:\/\/blog.ezworkapp.com\/power-query-da-cuu-vot-thuc-tap-nhu-nao-2.html\"><strong>S\u1ef1 quan tr\u1ecdng c\u1ee7a Power Queeery khi \u0111i l\u00e0m<\/strong><\/a><\/li>\n<\/ol>\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\/2024\/12\/vba101_92019-nho-63.gif\"><br \/>\n<\/a>\n<\/div>\n","protected":false},"author":1,"featured_media":2032,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2031","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-excel-nang-cao"],"_links":{"self":[{"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/posts\/2031","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=2031"}],"version-history":[{"count":0,"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/posts\/2031\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/media\/2032"}],"wp:attachment":[{"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/media?parent=2031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/categories?post=2031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ezworkapp.com\/index.php\/wp-json\/wp\/v2\/tags?post=2031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}