Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Format cells in a range with bold font and yellow background color
#1
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).
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Split text in cells with VBA Qomplainerz 0 407 07-27-2023, 11:09 AM
Last Post: Qomplainerz
  Count colored cells with VBA Qomplainerz 0 353 07-27-2023, 11:07 AM
Last Post: Qomplainerz
  Calculate the avg and color the cells when their values are above or below the avg Qomplainerz 0 421 07-27-2023, 10:41 AM
Last Post: Qomplainerz
  Protect specific cells with VBA Qomplainerz 0 374 07-27-2023, 10:39 AM
Last Post: Qomplainerz
  Find a specific value in a range and replace it with a new value Qomplainerz 0 379 07-27-2023, 10:38 AM
Last Post: Qomplainerz
  Sort data in a range with VBA Qomplainerz 0 362 07-27-2023, 09:43 AM
Last Post: Qomplainerz
  Format cells with conditional formatting in VBA Qomplainerz 0 351 07-27-2023, 08:16 AM
Last Post: Qomplainerz
  Loop to fill numbers in cells with VBA Qomplainerz 0 374 07-27-2023, 08:16 AM
Last Post: Qomplainerz
  Find the maximum value in a range with VBA Qomplainerz 0 362 07-27-2023, 07:54 AM
Last Post: Qomplainerz
  Formatting cells with VBA Qomplainerz 0 322 07-27-2023, 06:31 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 7 Guest(s)