replace是Range对象的一个方法,用于单元格替换.
Sub replaceTest() Application.ReplaceFormat.Interior.Color = vbGreen '指定lookat参数为Whole,从而避免将21等包含2的数字也替换掉' Range("b2:e4").Replace what:=2, replacement:=3, lookat:=xlWhole, ReplaceFormat:=True End Sub
Sub replaceTest() Application.ReplaceFormat.Interior.Color = vbGreen '指定lookat参数为Whole,从而避免将21等包含2的数字也替换掉' Range("b2:e4").Replace what:=2, replacement:=3, lookat:=xlWhole, ReplaceFormat:=True End Sub Sub FindLastRow() Dim r As Range 'Set r = Range("b2").End(xlDown)' Set r = Cells(Rows.Count, 2).End(xlUp) MsgBox r.Row End Sub Sub findTableLastNum() Dim r As Range, maxRow As Long, i As Long '循环扫描第2列到5列' For i = 2 To 5 '获取第i列最后一个数据的行号' Set r = Cells(Rows.Count, i).End(xlUp) '如果该行号大于之前找到的最大行号,则更新最大行号' If r.Row > maxRow Then maxRow = r.Row Next i MsgBox "最后一个数据在第" & maxRow & "行" End Sub