代码在附件,源码开放,d1单元格为需要查找的字符,点击按钮显示符合条件的全部行号和列号
先定义一个rng变量,在该列非空单元格中循环;
再定义一个str变量,用于存放符合条件的单元格地址;
if rng=指定条件 then
str=rng.address & str & ","
end if
最后去掉str的最后一个逗号,写入位置或者msgbox显示
Sub FindAll()
Dim a, rng1, rng2, Address1, Address2
a = "xxx"
Set rng1 = ActiveSheet.UsedRange.Find(What:=a, lookat:=xlWhole)
If rng1 Is Nothing Then Exit Sub
Address1 = rng1.Address(0, 0)
Set rng2 = ActiveSheet.UsedRange.FindNext(rng1)
Address2 = rng2.Address(0, 0)
Do Until Address1 = Address2
Set rng1 = Application.Union(rng1, rng2)
Set rng2 = ActiveSheet.UsedRange.FindNext(rng2)
Address2 = rng2.Address(0, 0)
Loop
rng1.Select
End Sub
那重复的是要哪一行?这种你要说清楚哦