Set currCell = .Range("I" & .Rows.Count).End(xlUp).Offset(1) currCell.Clear currCell.Value = "RGB(" & r & ", " & g & "," & b & ")" currCell.Interior.color = RGB(r, g, b) If GetContrastColor(currCell.Interior.color) = vbBlack Then currCell.Font.color = vbBlack El...
Function CountByFontColor(Col As Range, CountRange As Range) '根据字体颜色色计数 Application.Volatile Dim iCell As Range CountByFontColor = 0 For Each iCell In CountRange If iCell.Font.Color = Col.Font.Color Then CountByFontColor = CountByFontColor + 1 End If Next End Function Function...
Dim ws As Worksheet Dim myCell As range Dim prevCell As range Set ws = Application.ActiveSheet Set myCell = ws.Cells(1, 2) Set prevCell = myCell.Previous Debug.Print myCell.Value Debug.Print prevCell.Value 上一个单元格 5. Range 表示(多个)单元格区域 Dim myRange As range Dim ws As...
在 Excel VBA 中,您可以使用 Worksheet_SelectionChange 事件来监测单元格字体颜色的改变。以下是示例代码:Private Sub Worksheet_SelectionChange(ByVal Target As Range)Dim selCell As Range For Each selCell In Target If selCell.Font.ColorIndex <> xlAutomatic Then '此处是您自定义的代码 MsgBo...
cell.Characters(start, end - start + 1).Font.Color = RGB(255, 0, 0) ' 红色 End If Next cell End Sub 运行宏: 按F5运行宏,或者点击工具栏中的运行->运行子程序。 参考链接 Excel VBA 官方文档 Excel VBA 编程基础 解释 InStr函数用于查找字符串中第一次出现指定子字符串的位置。
1. Excel VBA - Cell Referencing 有四种方法: [b5].Value = 70 [c1:c10] = "Tutorials" Cells(8, 2).Value = "India" Range("a1").Value = "BeiJing" Range("a2:a10") = "Shanghai" 2. Excel VBA - Copy Paste Subcopy_paste()Range("a1:a10")="Tutorials"'1stMethodRange("b1:b10")=...
Sub test()On Error Resume Next For Each cell In Sheet1.UsedRange a = cell.Interior.ColorIndex cell.Select Selection.Font.ColorIndex = a cell.Interior.ColorIndex = -4142 Next end sub
Set cell = rng.Find(What:=5, LookIn:=xlValues, LookAt:=xlWhole)13、Font:设置字体 With rng.Font .Name = "黑体" .Bold = True .Color = vbRed .Size = 16 .Underline = xlUnderlineStyleSingleEnd With 14、Formula:设置单元格公式。rng.Formula = "=rand()"15、HorizontalAlignme...
cell = ActiveSheet.Range("B3:B15")'定义数据区域With cell.Clear.RowHeight = 20.EntireRow.Borders.Item(xlEdgeBottom).LineStyle = 1.EntireRow.Interior.Color = RGB(21, 221, 222)With .Font.Size = 12.Name = "微软雅黑"End WithEnd WithFor Each xcell In cellWith xcell.Value = VBA.Int((...
Use the RGB function to create a color value. ColorIndex returns or sets a value that represents the color of the font. FontStyle returns or sets the font style. Read/write String. Italic true if the font style is italic. Read/write Boolean. ...