How to quickly change font size based on Cell value in Excel?


In this article, users will be able to understand the process of changing the font size based on the provided values. This article briefs two common examples to demonstrate the required task. Benefits of learning this task −

  • It increases the readability of data by adjusting the font size. This ensures that the text becomes easy to read. Increasing the font size can be helpful for individuals with visual issues or when user wants to display the content on large screens or projectors.

  • The font size allows the user to create a visual emphasis and establish a hierarchy of information.

  • Increasing the font size is important to maintain the design and aesthetics of a document. Carefully selecting appropriate font sizes can enhance the visual appeal and professionalism of your work.

  • Modifying the font size is necessary to improve accessibility, making content more inclusive for individuals with varying visual abilities.

  • Changing font size helps the user to print and display the adjustment properly.

Example 1: To change the font size based on another column value in excel by using the VBA code:

Step 1

In this example will understand the process of changing the size based on the column value. Consider the data as shown in the below figure.

Step 2

Right-click on the sheet name and select the “View Code” option. For proper reference consider the below depicted image for reference −

Step 3

The above step will open a “Microsoft Visual Basic for Application” code window. The opened dialog box, contains few options, along with a blank code area −

Step 4

Paste the below provided code, to the editor −

' define method definition
Sub change_font()
   'declare required variables
   Dim range_x As Range
   Dim text_x As String
   Dim cell_x As Range
   On Error Resume Next
   ' if expression is greater than 1
   If ActiveWindow.RangeSelection.Count > 1 Then
      ' set the range selection
      text_x = ActiveWindow.RangeSelection.AddressLocal
   ' else block
   Else
   ' active sheet
      text_x = ActiveSheet.UsedRange.AddressLocal
   ' end of if block
   End If
   ' set the input box
   Set range_x = Application.InputBox("Select cells to change  font size:", "Excel", text_x, , , , , 8)
   ' if range is nothing
   If range_x Is Nothing Then Exit Sub
   ' if range is greater than 1
   If (range_x.Areas.Count > 1) Or (range_x.Columns.Count > 1) Then
      ' display message on data
      MsgBox "Select one column only", vbInformation, "Excel...."
      ' exit sub module
      Exit Sub
   ' end of if block
   End If
   ' screen update status to false
   Application.ScreenUpdating = False
   ' use for each cell in range
   For Each cell_x In range_x
      ' set font range
      cell_x.Font.Size = cell_x.Offset(, 1).Value
   ' next statement
   Next
   ' change screen update
   Application.ScreenUpdating = True
' end of sub module
End Sub

Step 5

Click on the “run” button, to execute the code. Consider below depicted image for reference −

Step 6

The above step will display a dialog box, with heading “Excel”. This dialog box contains the input area to access the data. Select the data from the provided excel sheet. For example, here, will be accessing the data from C3 to C5 cells. After that click on the “OK” button.

Step 7

The modified excel sheet is provided below −

Conclusion

This article contains a detailed and precise illustration to process the font size based on a cell value. This article contains a step-wise explanation for both examples.

Updated on: 29-Aug-2023

176 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements