|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
用rng(,jj*col+1)方法,容易出错。
Set MergeRng = Union(MergeRng, oRng)方法虽然麻烦,不容易出错。
- Sub del10210()
- Dim mRng As Range, Rng As Range, Rng1 As Range, Rng2 As Range
- Dim AddArr, WeaArr
- AddArr = Array("A2", "A11", "A20", "A29", "A38", "A47", "A56")
- WeaArr = Array("C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8")
- Set Rng = Range(Cells(1, 1).Formula)
- Set mRng = Rng(1, 1).MergeArea
-
- For jj = 0 To UBound(AddArr)
- Set Rng1 = Rng(, jj * (mRng.Columns.Count + 1) + 1)
- For jj1 = 0 To UBound(WeaArr)
- Rng1(3, jj1 + 1) = AddArr(jj) & WeaArr(jj1)
- Next jj1
- Debug.Print Rng1.Address
- Next jj
- End Sub
- ''
- Sub del20210()
- Dim MergeRng As Range, mRng As Range
- Dim Rng As Range, Rng1 As Range, Rng2 As Range
- Dim oRng As Range, oRng1 As Range, oRng2 As Range
- Dim AddArr, WeaArr
- AddArr = Array("A2", "A11", "A20", "A29", "A38", "A47", "A56")
- WeaArr = Array("C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8")
- Set Rng = Range(Cells(1, 1).Formula)
- Set MergeRng = Rng.Find(AddArr(0), LookAt:=xlWhole).MergeArea
- For jj = 1 To UBound(AddArr)
- Set oRng = Rng.Find(AddArr(jj)).MergeArea
- Set MergeRng = Union(MergeRng, oRng)
- 'Debug.Print MergeRng.Address
- Next jj
- Set mRng = Rng(1, 1).MergeArea
- ii = 10
- For jj = 1 To MergeRng.Areas.Count
- Set oRng = Cells(ii, MergeRng.Areas(jj).Column)
- ''
- For jj1 = 0 To UBound(WeaArr)
- oRng(, jj1 + 1) = AddArr(jj - 1) & WeaArr(jj1)
- Next jj1
-
- Next jj
- End Sub
复制代码
|
|