|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub del1()
- Dim Rng As Range, oRng As Range
- Dim Rng1 As Range, Rng2 As Range
- Dim Rr, Str
- Dim Num1, Num2, Num, oNum
- With Sheet1
- For jj = 1 To 2
- Set Rng = .Range(.Cells(1, jj).Formula)
- RelationData Rng.Areas(1), Rng.Areas(2)
- Next jj
- End With
- End Sub
- Function RelationData(oRng1 As Range, oRng2 As Range)
- Dim Rng As Range, oRng As Range
- Dim Rng1 As Range, Rng2 As Range
- Dim Rr, Str, Num, Num1, Num2
- Num = 5
- Debug.Print oRng1.Address, oRng2.Address
- For Each Rng1 In oRng1
- Rr = 1
- For Each Rng2 In oRng2
- If Rng2 > 0 Then
- oNum = Num
- ElseIf Rng2 < 0 Then
- oNum = -Num
- End If
- ''
- If Rng2 > 0 And Rng2 < 1 Then
- Str = Application.WorksheetFunction.Ceiling(Rng2, oNum / 1440)
- If Format(Rng1, "hh:mm") = Format(Str, "hh:mm") Then
- If Rr = 1 Then
- Set oRng = Rng2
- Else
- Set oRng = Union(oRng, Rng2)
- End If
- Rr = Rr + 1
- End If
- Else
- Str = Application.WorksheetFunction.Ceiling(Rng2, oNum)
- If Val(Rng1) = Val(Str) Then
- 'Debug.Print Rr, Str, Rng1
- If Rr = 1 Then
- Set oRng = Rng2
- Else
- Set oRng = Union(oRng, Rng2)
- End If
- Rr = Rr + 1
- End If
- End If
- Next Rng2
- 'Stop
- If Not oRng Is Nothing Then
- Rng1(, 3) = "=" & oRng.Address(0, 0)
- Set oRng = Nothing
- End If
- 'Debug.Print Rng1(, 3).Address
- Next Rng1
- End Function
复制代码
|
|