Selection.Font.Color = RGB(10, 201, 88) ActiveCell.Font.ThemeColor = xlThemeColorAccent2 Selection.Font.ColorIndex = 49 This table shows the index number for colours in the default colour palette. Background Colour of Cell/s See font colour above for different ways of specifying colour. Sel...
如果要根据条件来改变单元格中字体或字号,可以用VBA来实现。下面的VBA代码将指定区域(H2:H500)中大于5000而小于10000的数值设置为“黑体”、“16”,而将指定区域中其他单元格的字体和字号设置为“宋体”、“11”。 Sub ConditionalFont()Dim rCell As RangeDim Rng As RangeSet Rng = Range("H2:H500")Applicati...
首先,按下Alt+F11打开Visual Basic for Applications(VBA)编辑器。然后,在“插入”菜单中选择“模块”,在代码窗口中输入以下VBA代码: Sub AdjustFontSize() For Each cell In Selection cell.Font.Size = 12 '设置字体大小为12 Next cell End Sub 在这个例子中,VBA代码将选定单元格范围内的所有单元格的字体大小...
Dim ws As Worksheet Dim myCell As range Dim nextCell As range Set ws = Application.ActiveSheet Set myCell = ws.Cells(1, 1) Set nextCell = myCell.Next Debug.Print myCell.Value Debug.Print nextCell.Value 上述代码A1单元格的下一个单元格, 输出A1和B1单元格的内容 4. Previous 和Next的意思...
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((...
VBA Font Size Font object also gives you access to the size property of the font. Let’s say you want to apply the font size of 16 to the font in the cell A1, the code would be: Range("A1").Font.Size = 16 If you want to apply font size to all cells in a worksheet you can...
(Visual Basic Application) VBA(Visual Basic for Application)是Microsoft Office系列软件的内置编程语言,其语法结构与Visual Basic编程语言互相兼容,采用的是面向对象的编程机制和可视化的编程环境。 第一节 标识符 一.
) Range("A1:Y161").Select Selection.FormatConditions.Delete Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _ Formula1:="=""(此项空白)""" With Selection.FormatConditions(1).Font .Name = "楷体" .Size = 8 End WithEnd Sub结果系统提示...
Frame2.TextRange.Font.Size=12' 设置字体大小.TextFrame2.TextRange.Font.Bold=msoTrue' 设置字体加粗.TextFrame2.VerticalAnchor=msoAnchorMiddle' 垂直居中.TextFrame2.HorizontalAnchor=msoAnchorCenter' 水平居中EndWithi=i+1Nextcell' 添加颜色图例以解释颜色和销量之间的关系AddLegendwsEndSub...