Set rng = ws.Range("A1:A" & ws.Cells(ws.Rows.Count, "A").End(xlUp).Row) ' 遍历A列的单元格,将包含"$"的单元格字体设置为粗体 For Each cell In rng ' 检查单元格是否包含"$" If InStr(cell.Value, emoji) > 0 Then ' 如果包含"$",则将字体设置为粗体 cell.Font.Bold = True End If Next cell End Sub 以上是我自己的学习结果
Debug.Print prevCell.Value 上一个单元格 5. Range 表示(多个)单元格区域 Dim myRange As range Dim ws As Worksheet Set ws = Application.ActiveSheet 'Set myRange = ws.range(Cells(1, 1), Cells(2, 2)) Set myRange = ws.range("A1,B2,C3:D4") myRange.Select 选中了多个不连续的单元格 6...
12、Find:查找包含指定值的单元格: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.Formul...
新建条件样式 Private Sub CommandButton1_Click()With Range("A4:F10").FormatConditions.Add(xlCellValue, xlGreater, "=$B$3")With .Borders '设置边框样式.LineStyle = xlContinuous.Weight = xlThin.ColorIndex = 9End WithWith .Font '设备字体样式.Bold = True.ColorIndex = 3End WithEnd WithEnd Sub...
.TextFrame2.TextRange.Font.Bold = msoTrue ' 设置字体加粗 .TextFrame2.VerticalAnchor = msoAnchorMiddle ' 垂直居中 .TextFrame2.HorizontalAnchor = msoAnchorCenter ' 水平居中 End With i = i + 1 Next cell ' 添加颜色图例以解释颜色和销量之间的关系 AddLegend wsEnd Sub' 根据...
下面是VBA帮助中给出的一些示例代码。 下列表达式是等价的: [A1].Value=25 Evaluate(“A1”).Value=25 trigVariable=[SIN(45)] trigVariable=Evaluate[“SIN(45)”] Set firstCellInSheet =Workbooks(“BOOK1.XLS”).Sheets(4).[A1] Set firstCellInSheet = Workbooks(“BOOK1.XLS”).Sheets(4).Evaluate...
VBA在Excel中的应用(二) AutoFilter 1. 确认当前工作表是否开启了自动筛选功能 Sub filter() If ActiveSheet.AutoFilterMode Then MsgBox "Turned on" End If End Sub 当工作表中有单元格使用了自动筛选功能,工作表的AutoFilterMode的值将为True,否则为False。
格式化代码 这些VBA代码将帮助您使用一些特定的条件和条件来格式化单元格和范围。 11. 从选择中突出显示重复项 Sub HighlightDuplicateValues() Dim myRange As Range Dim myCell As Range Set myRange = Selection For Each myCell In myRange If WorksheetFunction.CountIf(myRange, myCell.Value) > 1 Then...
Set dicFilter = CreateObject("Scripting.Dictionary") For i = 1 To lastCol If arr(1, i) = Me.CmbFilterColumn Then filterCol = i Exit For End If Next For i = 1 To lastCol If arr(1, i) = Me.CmbSplitColumn Then SplitCol = i Exit For End If Next For i = 2 To lastRow If ...
```VBA Sub FormatCells() Dim rng As Range Dim cell As Range Set rng = Range("A1:A10") '设置要应用条件格式的单元格范围 For Each cell In rng If cell.Value = "Pass" Then With cell.Font .Bold = True .Size = 14 .Color = RGB(0, 0, 255) '蓝色 End With ...