QP School
Format cells in a range with bold font and yellow background color - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48)
+--- Thread: Format cells in a range with bold font and yellow background color (/showthread.php?tid=5272)



Format cells in a range with bold font and yellow background color - Qomplainerz - 07-27-2023

Example:

Sub FormatCellsInRange()
    Dim ws As Worksheet
    Dim formatRange As Range

    'Set the worksheet where the data is located
    Set ws = ThisWorkbook.Sheets("Sheet1")

    'Set the range of cells to be formatted (adjust the range as per your data)
    Set formatRange = ws.Range("A1:B5")

    'Apply formatting to the range
    With formatRange
        .Font.Bold = True
        .Interior.Color = RGB(255, 255, 0) 'Yellow color
    End With
End Sub

Explanation:

The code defines a subroutine named FormatCellsInRange.
It declares variables for the worksheet (ws) and the range of cells to be formatted (formatRange).
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the data is located.
Set formatRange = ws.Range("A1:B5") sets the range A1:B5 to be formatted. 
Adjust the range as per your data.
The With block is used to apply formatting to the formatRange.
.Font.Bold = True makes the font bold for all cells in the range.
.Interior.Color = RGB(255, 255, 0) sets the background color of all cells in the range to yellow using the RGB value (255, 255, 0).