|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 duquancai 于 2018-8-10 23:38 编辑
- Sub main()
- Dim a(), b(), d As Object, i&, j&
- Worksheets(1).Select: Rows("1:2").Interior.Pattern = xlNone
- If Not getC(a, Rows(1), "苹果") Then MsgBox "不玩!": Exit Sub
- If Not getC(b, Rows(2), "橘子") Then MsgBox "不玩!": Exit Sub
- Set d = CreateObject("Scripting.Dictionary")
- For i = LBound(a) To UBound(a): d(CStr(a(i))) = vbNullString: Next
- For i = LBound(b) To UBound(b)
- If d.exists(CStr(b(i))) Then j = j + 1: Range(Cells(1, b(i)), Cells(2, b(i))).Interior.Color = 65535
- Next
- MsgBox IIf(j, "有" & j & "个同列", "没得同列的")
- End Sub
- Function getC(ByRef arr, ByVal rng As Range, ByVal str) As Boolean
- Dim c As Range, FirstAddress$, n&
- Set c = rng.Find(str, LookIn:=xlValues, lookat:=xlWhole)
- If Not c Is Nothing Then
- FirstAddress = c.Address
- Do
- n = n + 1: ReDim Preserve arr(1 To n)
- arr(n) = c.Column: Set c = rng.FindNext(c)
- Loop Until c.Address = FirstAddress
- getC = True
- End If
- End Function
复制代码 |
|