Category: VBA macros

Macros in Excel for beginners, VBA excel examples, Excel VBA programming, VBA macros and tutorials

Remove blank rows inside cell [excel VBA]

remove-blank-rows-inside-cell-excel-vba

We can create new line/row inside a cell by pressing ALT+ENTER in MS Excel. If you come across a situation where you want to remove blank rows/lines inside the cell, then you can’t remove them using trim method. Below code helps you to remove them automatically using VBA code. Sub removeBlankRowsInsidecell() Dim cellWithBlankRows, cellWithoutBlankRows ‘Remove […]

[Excel VBA code] Convert a string to Uppercase letters

excel-vba-convert-string-to-uppercase-output

Excel VBA code to convert a string to uppercase letters. It converts all lowercase letters to uppercase. Sub convertStringToUpperCase() ‘macro to convert a string to uppercase letters exString = “helLo how Are yOU” ‘ Example string stringAfterConversion = StrConv(exString, vbUpperCase) ‘ Converting the string letters to uppercase MsgBox (“string after conversion to uppercase is – […]

VBA code to capitalize each word of a string [Excel]

capitalize-each-word-string-VBA-excel

Below is the Excel VBA code to capitalize each word of a string. Sub capitalizeEachWordOfString() ‘macro to capitalize each word of a string exString = “helLo how Are yOU” ‘ Example string stringAfterCapitalized = StrConv(exString, vbProperCase) ‘ capitalizing each word of the string MsgBox (“string after its each word is capitalized is – ” + […]

VBA macro to find duplicates in excel

macro-duplicates-highlighted-in-red

VBA macro to find duplicates in excel sheet. This macro finds the duplicates in user selected range and highlights them in light red color. Also see VBA macro to remove duplicates VBA code to find and highlight duplicates Sub findAndHighlightDuplicates() Selection.FormatConditions.AddUniqueValues Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority Selection.FormatConditions(1).DupeUnique = xlDuplicate With Selection.FormatConditions(1).Font .Color = -16383844 .TintAndShade = 0 End With […]

Macro to extract file name from file path [Excel VBA]

Excel VBA macro to extract file name from file path. This macro extracts the string (file name) which is between dot (.) and backslash(\) delimiters (from right side). Sub extractFileNameFromFilePath() ‘ This macro shows you how to extract filename from filepath ‘ It extracts the filename which is between delimiters dot and backslash filePath = […]

VBA macro to delete empty columns in excel

Excel VBA macro to delete empty columns. Just run this macro, enter number of columns you want to check and the macro checks (starting from first column) and deletes all empty columns within the selected number of columns. In the macro, you can also find VBA syntax to delete empty row and to check whether a […]