|
发表于 2022-1-11 17:16
|
显示全部楼层
本楼为最佳答案
- Option Explicit
- Sub demo()
- On Error Resume Next
- Dim arr, h, i As Integer
- h = Sheet1.Range("a65536").End(xlUp).Row
- arr = Sheet1.Range("a2:b" & h)
- If h = 1 Then End
- Union(Sheet1.Range("h3:j" & h), Sheet1.Range("m3:m" & h), Sheet1.Range("p3:p" & h)) = ""
- Call 固定组
- Dim m1 As Integer, m2 As Integer, k As Integer, x As Integer, y As Integer
- Dim d As New Dictionary
- For i = 10 To 18
- k = k + 1
- m1 = Sheet1.Cells(65536, i - 1).End(xlUp).Row
- m2 = Sheet1.Cells(65536, i).End(xlUp).Row
- If k = 1 Then
- Call 排序天数
- For x = 2 To h
- d(Sheet1.Cells(x, 1).Value) = ""
- Next x
- For x = 3 To m2
- d.Remove Sheet1.Cells(x, i).Value
- Next x
- ElseIf k = 2 Then
- If Sheet1.Cells(2, i).Value = "" Or Sheet1.Cells(2, i).Value = 0 Then
- Sheet1.Cells(3, i).Resize(h) = ""
- ElseIf m2 - 2 > Sheet1.Cells(2, i).Value Then
- MsgBox Sheet1.Cells(1, i).Value & "的人数超出,请减少"
- Sheet1.Range("a2:b" & h) = arr
- End
- ElseIf m2 - 2 = Sheet1.Cells(2, i).Value Then
- ElseIf m2 - 2 < Sheet1.Cells(2, i).Value Then
- For x = 3 To m2
- d.Remove Sheet1.Cells(x, i).Value
- Next x
- Sheet1.Cells(x, i).Resize(Sheet1.Cells(2, i).Value - (m2 - 2)) = Application.Transpose(d.Keys)
- End If
- Else
- 'k=3
- If Sheet1.Cells(2, i).Value = "" Or Sheet1.Cells(2, i).Value = 0 Then
- Sheet1.Cells(3, i).Resize(h) = ""
- ElseIf m2 - 2 > Sheet1.Cells(2, i).Value Then
- MsgBox Sheet1.Cells(1, i).Value & "的人数超出,请减少"
- Sheet1.Range("a2:b" & h) = arr
- End
- ElseIf m2 - 2 = Sheet1.Cells(2, i).Value Then
- ElseIf m2 - 2 < Sheet1.Cells(2, i).Value Then
- For x = 3 To m1
- d.Remove Sheet1.Cells(x, i - 1).Value
- Next x
- For x = 3 To m2
- d.Remove Sheet1.Cells(x, i).Value
- Next x
- Sheet1.Cells(x, i).Resize(Sheet1.Cells(2, i).Value - (m2 - 2)) = Application.Transpose(d.Keys)
- End If
- k = 0
- End If
- Next i
- Sheet1.Range("a2:b" & h) = arr
- End Sub
- Sub 固定组()
- Dim d1 As Object
- Dim d2 As Object
- Dim d3 As Object
- Dim d4 As Object
- Dim d5 As Object
- Dim d6 As Object
- Dim i As Integer, arr
- arr = Sheet1.Range("a2:b" & Sheet1.Range("b65536").End(xlUp).Row)
- If Sheet1.Range("b65536").End(xlUp).Row = 1 Then End
- Set d1 = CreateObject("scripting.dictionary")
- Set d2 = CreateObject("scripting.dictionary")
- Set d3 = CreateObject("scripting.dictionary")
- Set d4 = CreateObject("scripting.dictionary")
- Set d5 = CreateObject("scripting.dictionary")
- Set d6 = CreateObject("scripting.dictionary")
- Dim brr, f, x
- brr = Array("考务组", "纪检组", "24日领队", "25日领队", "26日领队", "无")
- For i = 1 To UBound(arr, 1)
- x = Application.Match(arr(i, 2), brr, 0)
- If x = 1 Then
- d1(arr(i, 1)) = arr(i, 2)
- ElseIf x = 2 Then
- d2(arr(i, 1)) = arr(i, 2)
- ElseIf x = 3 Then
- d3(arr(i, 1)) = arr(i, 2)
- ElseIf x = 4 Then
- d4(arr(i, 1)) = arr(i, 2)
- ElseIf x = 5 Then
- d5(arr(i, 1)) = arr(i, 2)
- Else
- d6(arr(i, 1)) = arr(i, 2)
- End If
- Next i
- Sheet1.Range("h3").Resize(d1.Count) = Application.Transpose(d1.Keys)
- Sheet1.Range("i3").Resize(d2.Count) = Application.Transpose(d2.Keys)
- Sheet1.Range("j3").Resize(d3.Count) = Application.Transpose(d3.Keys)
- Sheet1.Range("m3").Resize(d4.Count) = Application.Transpose(d4.Keys)
- Sheet1.Range("P3").Resize(d5.Count) = Application.Transpose(d5.Keys)
- d1.RemoveAll: d2.RemoveAll: d3.RemoveAll: d4.RemoveAll: d5.RemoveAll: d6.RemoveAll
- End Sub
- Sub 排序天数()
- Dim arr, h
- h = Sheet1.Range("a65536").End(xlUp).Row
- arr = Sheet1.Range("a2:b" & h)
- If h = 1 Then End
- Sheet1.Range("a1:c" & h).Sort Range("c1")
- End Sub
复制代码 你早一些把需求说清楚就不会有这些问题了。看下是否ok了
|
|