{"id":242787,"date":"2022-08-09T21:34:57","date_gmt":"2022-08-09T21:34:57","guid":{"rendered":"https:\/\/vmlogger.com\/excel\/?p=242787"},"modified":"2022-08-17T18:29:59","modified_gmt":"2022-08-17T18:29:59","slug":"changing-case-of-existing-text","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2022\/08\/changing-case-of-existing-text\/","title":{"rendered":"VBA Code – Change the Case of existing Texts in a Sheet"},"content":{"rendered":"
[et_pb_section fb_built=”1″ admin_label=”section” _builder_version=”4.16″ da_disable_devices=”off|off|off” global_colors_info=”{}” da_is_popup=”off” da_exit_intent=”off” da_has_close=”on” da_alt_close=”off” da_dark_close=”off” da_not_modal=”on” da_is_singular=”off” da_with_loader=”off” da_has_shadow=”on”][et_pb_row admin_label=”row” _builder_version=”4.16″ background_size=”initial” background_position=”top_left” background_repeat=”repeat” global_colors_info=”{}”][et_pb_column type=”4_4″ _builder_version=”4.16″ custom_padding=”|||” global_colors_info=”{}” custom_padding__hover=”|||”][et_pb_text _builder_version=”4.17.6″ _module_preset=”default” global_colors_info=”{}”]In this article, I am going to share a VBA code that can be used to change the cases of texts written in an excel worksheet. This can be used to enforce proper casing on texts written in a sheet or cell range. As you know – casing can be of 3 types: 1. lower, 2. UPPER or 3. Proper. Using this function you would be able to do any of this.<\/p>\n
You can convert any text to lower, upper or proper cases in excel formula like below:<\/p>\n
Casing Formula<\/p><\/div>\n
Now let’s do this by VBA code. Using VBA code, you would be able to do it automatically without using any formula.<\/p>\n
The following function will be run on the selected area on a worksheet and convert the texts into a cell in lower, upper or proper case. You can also write a VBA code, which can change the case as soon as you type in a cell or cell range. This way, you can enforce user to type it a format you expect them to type. Incase they don’t type, VBA will automatically correct it in the correct format.<\/p>\n For example, in an Excel Form, if you want user to type their name in all Capital Letters, then you can use the following code in Worksheet_Change <\/strong>procedure. You are expected to type the Name in cell A10 <\/strong><\/p>\n I hope you liked the article and learned something new today. Try this in your application and share your feedback. Thank you so much.<\/p>\n<\/div>\n [\/et_pb_text][et_pb_blurb title=”You may like these too…” use_icon=”on” font_icon=”||fa||900″ _builder_version=”4.17.6″ _module_preset=”0249c68e-4de8-4f44-84ff-a9b1850785b6″ hover_enabled=”0″ global_colors_info=”{}” sticky_enabled=”0″]<\/p>\n [\/et_pb_blurb][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n<\/span>","protected":false},"excerpt":{"rendered":" In this article, I am going to share a VBA code that can be used to change the cases of texts written in an excel worksheet. This can be used to enforce proper casing on texts written in a sheet or cell range. As you know – casing can be of 3 types: 1. lower, […]<\/p>\n","protected":false},"author":45,"featured_media":242800,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1672,1246],"tags":[],"class_list":["post-242787","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-excel-formula","category-macro"],"yoast_head":"\n
\nNote:<\/span> Following code will ignore those cells which already has formula in it. This is important so that you don’t mess with the formula in a cell.<\/p>\n\nSub ChangeCase()\n Dim cellRange As Range\n Application.EnableEvents = False\n For Each cellRange In Selection.SpecialCells(xlCellTypeConstants, xlTextValues).Cells\n cellRange.Value = StrConv(Rng.Text, vbUpperCase)\n 'Similar to changing UpperCase, you can use \n 'vbLowerCase and vbProperCase for LowerCase and ProperCase respectively\n Next cellRange\n 'enable vba events back again\n Application.EnableEvents = True\nEnd Sub\n<\/pre>\n
\nPrivate Sub Worksheet_Change(ByVal Target As Range)\n If Not Application.Intersect(Range(\"A10\"), Target) Is Nothing Then\n Application.EnableEvents = False\n If IsNumeric(Target.Value) = False Then\n Target.Value = StrConv(Target.Text, vbUpperCase)\n End If\n Application.EnableEvents = True\n End If\nEnd Sub\n<\/pre>\n
Conclusion:<\/h2>\n
\n\n