Excel VBA 修改字体问题
发布网友
发布时间:2022-04-30 14:00
我来回答
共2个回答
热心网友
时间:2022-06-22 21:41
字体不加粗,将.Font.Bold=True里的True改为False(有两处)
将F列改为其他 列,请将所有引号里的"F"改为你要的列号字母就行 (有10处)
以下是为你修改后的代码,请将第2行的"F"改为你要的列号
Sub Test()
Const L ="F" '以后如要改到其他列,只要改这个地方
Dim rng As Range, rngC As Range
Dim intRow As Long
Dim cntRow As Long
Dim cnt As Long
Dim n As Long
Dim dat()
Dim strA As String
Application.ScreenUpdating = False
strA = Empty
intRow = Range("A65536").End(xlUp).Row
Set rng = Range("A2:A" & intRow)
cntRow = rng.Rows.Count
strA = "*" & InputBox("输入要搜索的内容") & "*"
Debug.Print strA
If strA = "**" Then Exit Sub
cnt = Application.WorksheetFunction.CountIf(rng, strA)
ReDim dat(1 To cnt, 1 To 1)
n = 1
For Each rngC In rng
If Application.WorksheetFunction.CountIf(rngC, strA) = 1 Then
dat(n, 1) = rngC
n = n + 1
End If
Next rngC
With Range(L & "1:" & L & Range(L & "65536").End(xlUp).Row)
.ClearContents
.ClearFormats
End With
Range(L & "1") = "搜索结果"
With Range(L & "1")
.Interior.ColorIndex = 20
.Font.Name = "宋体" '这里是字体
.Font.Size = 12 '这里是字体大小
.Font.Bold = False '标题行是否加粗
.Borders.LineStyle = xlContinuous
.HorizontalAlignment = xlCenter
End With
With Range(L & "2:" & L & n)
.Value = dat
.Font.Name = "宋体" '这里是字体
.Font.Size = 12 '这里是字体大小
.Borders.LineStyle = xlContinuous
.Font.Bold = False '搜索结果是否加粗
.Interior.ColorIndex = 19
.HorizontalAlignment = xlCenter
End With
Range(L & "2:" & L & n).Sort key1:=Range(L & "2"), order1:=xlAscending
MsgBox (" 共 " & n - 1 & " 件被搜索.")
Application.ScreenUpdating = True
End Sub
热心网友
时间:2022-06-22 21:42
关注