|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
表2找位置的更新,思路可能需要优化,但暂时只能想出这个笨方法
- Sub 表2查找错误位置()
- Dim vData As Variant, vRow As Variant, vCol As Variant
- Dim dicRow As Object, dicCol As Object, dicEmpty As Object, vKey As Variant
- Dim rRange As Range, rStart As Range
- Set dicRow = CreateObject("Scripting.Dictionary")
- Set dicCol = CreateObject("Scripting.Dictionary")
- Set dicEmpty = CreateObject("Scripting.Dictionary")
- Set dicEmpty(0) = CreateObject("Scripting.Dictionary") '行的空格数
- Set dicEmpty(1) = CreateObject("Scripting.Dictionary") '列的空格数
-
- Set rStart = [B34]
- vData = rStart.Resize(12, 8).Value
- For vRow = 2 To UBound(vData)
- For vCol = 2 To UBound(vData, 2)
- vData(vRow, 1) = vData(vRow, 1) - vData(vRow, vCol)
- vData(1, vCol) = vData(1, vCol) - vData(vRow, vCol)
- If IsEmpty(vData(vRow, vCol)) Then
- dicRow(vRow) = dicRow(vRow) + 1
- dicCol(vCol) = dicCol(vCol) + 1
- End If
- Next
- Next
-
- For Each vRow In dicRow.Keys
- For Each vCol In dicCol.Keys
- If vData(vRow, 1) > 0 Then dicEmpty(0)(dicRow(vRow)) = dicEmpty(0)(dicRow(vRow)) & "|" & vRow & "," & vCol
- If vData(1, vCol) > 0 Then dicEmpty(1)(dicCol(vCol)) = dicEmpty(1)(dicCol(vCol)) & "|" & vRow & "," & vCol
- If vData(vRow, 1) > 0 And vData(1, vCol) > 0 And IsEmpty(vData(vRow, vCol)) Then
- dicEmpty(vRow & "," & vCol) = 0
- If rRange Is Nothing Then
- Set rRange = Cells(rStart.Row - 1 + vRow, rStart.Column - 1 + vCol)
- Else
- Set rRange = Union(rRange, Cells(rStart.Row - 1 + vRow, rStart.Column - 1 + vCol))
- End If
- End If
- Next
- Next
-
- rStart.Offset(1, 1).Resize(11, 7).Interior.Color = xlNone
- If Not rRange Is Nothing Then rRange.Interior.Color = 255
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|