Excel VBA Code to Change Fonts in Specific Range
Click here to download the workbook which contains the below code
Copy below code and paste it in the VBA Code Window. Click F5 to execute the code.
Sub Fonts_Text() 'www.comexcelhub.com 'This Code will change font colors for specific range, update values, apply borders to the range 'Declaration of variable to store Range Dim rng As Range 'Updating range info to variable Set rng = ThisWorkbook.Sheets("Sheet1").Range("A1:A10") 'Updating the Text in the Excel range rng = "www.comexcelhub.com" 'Changeing the Cell colors in the range rng.Interior.Color = vbYellow 'Changeing the text colors in the range rng.Font.Color = vbRed 'Applyintg borders all sides to the range rng.Borders.LineStyle = xlContinuous 'Adjusting Columnwdith as per text to the range rng.EntireColumn.AutoFit End Sub
Explanation of Code Lines
Below is the Declaration of the variable to store Range
Line1: Dim rng As Range
Below Code is to update range info to variable
Line2: Set rng = ThisWorkbook.Sheets(“Sheet1”).Range(“A1:A10”)
Below code is to update the Text in the Excel range
Line3: rng = “www.comexcelhub.com”
Below code is to change the Cell colours in the range to Yellow
Line4: rng.Interior.Color = vbYellow
Below Code is to change the text colours in the range to Red
Line5: rng.Font.Color = vbRed
Below Code is to applying borders all sides to the range
Line6: rng.Borders.LineStyle = xlContinuous
Below Code is to Adjusting Columnwdith as per text in the range
Line7: rng.EntireColumn.AutoFit
Video on the above code will be available here shortly……………….