|
拆分汇总二合一
- Sub 分分合合()
- Dim arr, brr, brrTmp
- Dim myrow%, myrowB%, mycolB%
- myrowA = Range("A" & Rows.Count).End(xlUp).Row
- myrowB = Range("B" & Rows.Count).End(xlUp).Row
- If myrowA > myrowB Then myrow = myrowA Else myrow = myrowB
-
- arr = Range("A1:A" & myrowA).Value
- For i = 2 To myrow
- If Range("A" & i) <> "" And _
- Range("B" & i) = "" Then '如果A有B无
- brr = Split(arr(i, 1), ",")
- Range("B" & i). _
- Resize(1, UBound(brr) + 1).Value = brr
- End If
-
- If Range("A" & i) = "" And _
- Range("B" & i) <> "" Then '如果A无B有
- mycolB = Range("B" & i).End(xlToRight).Column - 1
- brr = Range("B" & i).Resize(1, mycolB).Value
- brrTmp = Application.Transpose(Application.Transpose(brr)) '二维转一维
- Range("A" & i).Value = Join(brrTmp, ",")
- End If
- Next
- End Sub
复制代码 |
|