|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
这样的
- Sub Upper_X()
- Dim ar_Up, ar_Parent, i, j
- With Sheet1
- ar_Up = .[A1].CurrentRegion
- ReDim Preserve ar_Up(1 To UBound(ar_Up), 1 To 3): ar_Up(1, 3) = "父子关联": ar_Up(2, 3) = ar_Up(2, 2)
- For i = 3 To UBound(ar_Up)
- For j = i To 1 Step -1
- Select Case ar_Up(i, 1)
- Case Is <> 1: If ar_Up(i, 1) > ar_Up(j, 1) Then ar_Up(i, 3) = ar_Up(j, 2) & "-" & ar_Up(i, 2): Exit For
- Case Else: ar_Up(i, 3) = ar_Up(2, 2)
- End Select
- Next
- Next
- .[L1].CurrentRegion.ClearContents
- .[L1].Resize(UBound(ar_Up), UBound(ar_Up, 2)) = ar_Up
- End With
- End Sub
复制代码
|
|