#2
厨师王德榜2022-06-13 16:14
供你参考 ,只写了第一个要求, 第二个要求 你参考这个代码,举一反三 ,不难写出 :
程序代码: Sub FindCell() ' 查找班级课程表、教师课程表中的“*课程表”, ' Dim sht As Worksheet, rng As Range, lStop As Boolean Dim arrsht() arrsht = Array("教师课程表", "班级课程表") Worksheets("要求").Activate For Each shtName In arrsht lStop = False Set sht = Worksheets(shtName) sht.Activate sht.Range("A1").Activate If InStr(1, sht.Range("A1").Value, "课程表", vbTextCompare) > 0 Then Call SetFont1(sht.Range("A1")) End If While lStop = False Set rng = Cells.Find(What:="课程表", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _ xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _ , MatchByte:=False, SearchFormat:=False) ad1 = rng.AddressLocal rng.Activate If rng.Row = 1 Then lStop = True Else Call SetFont1(rng) rng = sht.Cells.FindNext(After:=ActiveCell) ad1 = rng.AddressLocal End If Wend Next shtName End Sub Sub SetFont1(rng1 As Range) '设置 字体为“仿宋_GB2312”,字号为“20”,字体颜色为红色,背景色为黄色。 With rng1.Font .Name = "仿宋_GB2312" .Size = 20 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With With rng1.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 65535 .TintAndShade = 0 .PatternTintAndShade = 0 End With With rng1.Font .Color = -16776961 .TintAndShade = 0 End With End Sub [此贴子已经被作者于2022-6-13 16:24编辑过] |
2、用VBA查找班级课课表、教师课程表中的“早自习、上午、下午、晚自习”,并设置“早自习、上午、下午、晚自习”的字体为“仿宋_GB2312”,字号为“18”号。
只有本站会员才能查看附件,请 登录