excel的vba问题,我想用vba查找所有有蓝颜色字体的单元格并选出来。 代码应该怎么写

这是我录的宏,运行后错误91:对象变量或with块变量未设置 请问如何解决?

Sub 宏1()
'
' 宏1 宏
'
'
With Application.FindFormat.Font
.Subscript = False
.TintAndShade = 0
End With
Range("A3:AL3").Select
Application.FindFormat.Clear
Application.FindFormat.NumberFormat = "@"
With Application.FindFormat
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
With Application.FindFormat.Font
.Name = "Tahoma"
.FontStyle = "加粗"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.Underline = xlUnderlineStyleNone
.Color = -65536
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Application.FindFormat.Borders(xlLeft).LineStyle = xlNone
Application.FindFormat.Borders(xlRight).LineStyle = xlNone
With Application.FindFormat.Borders(xlBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Application.FindFormat.Borders(xlDiagonalDown).LineStyle = xlNone
Application.FindFormat.Borders(xlDiagonalUp).LineStyle = xlNone
With Application.FindFormat.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Application.FindFormat.Locked = True
Application.FindFormat.FormulaHidden = False
Cells.Find(what:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, MatchByte:=False, SearchFormat:=True).Activate
End Sub
每运行完一个with 中间的值都会变成 = <对象变量或with块变量未设置>
没运行完with的时候 = 什么都还是正常的
然后到cells.find().activate 的时候报错

第1个回答  2016-05-28
Public C '定义全局变量CPrivate Sub Worksheet_SelectionChange(ByVal Target As Range)On Error Resume Next Dim one, c1%If Target.Column > 1 And Target.Column 13 Then For one = 4 To 12 '因为你的数据在第4行到第12行之间 If Cells(one, c1) = Cells(one, C) Then '比较两列的数据 Cells(one, c1).Interior.ColorIndex = 3 '涂颜色 End If Next '比较下一个 C = 0 '清空CEnd IfEnd Sub用法: 代码粘贴在表1的代码页中 1、在数据1中要比较的那列随便选一个单格 2、在数据2中要比较的那列随便选一个单格

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网