|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 查询并合并单元格()
- Dim i As Long, j As Long, SL As Long
- Dim HuoZhu As String
- Dim Kshc As Long, Jghs As Long
- SL = 1
- Kshc = 9
- Jghs = 6
- With Sheets("明细表")
- i = .Range("a65536").End(xlUp).Row
- barr = .Range("A1:G" & i)
- HuoZhu = .Cells(3, 2)
- End With
- ReDim carr(1 To i * Jghs, 1 To UBound(barr, 2))
- For i = 1 To UBound(barr)
- If barr(i, 2) = HuoZhu Then
- For j = 1 To UBound(barr, 2)
- carr(SL, j) = barr(i, j)
- Next j
- SL = SL + Jghs
- End If
- Next i
- Sheets("期望效果").Cells(Kshc, 1).Resize(SL, UBound(barr, 2)) = carr
- For i = 1 To SL - 1 Step Jghs
- For j = 1 To UBound(barr, 2)
- Range(Cells(i + Kshc - 1, j), Cells(i + Kshc + Jghs - 2, j)).Select
- If Selection.MergeCells = False Then
- Selection.Merge
- End If
- Next j
- Next i
- MsgBox "查询、合并单元格完成!"
- End Sub
复制代码 |
|