返回列表 上一主題 發帖

[發問] 儲存格合併

回復 1# jcchiang
  1. Sub ex()
  2. Application.DisplayAlerts = False
  3. Range("A1:G19").UnMerge
  4. For i = 1 To Range("A1:G19").Columns.Count
  5.    If Application.CountBlank(Range("A1:G19").Columns(i)) > 0 Then
  6.       Set Rng = Range("A1:G19").Columns(i).SpecialCells(xlCellTypeBlanks)
  7.       Union(Rng, Rng.Offset(-1, 0)).Merge
  8.    End If
  9. Next
  10. Application.DisplayAlerts = True
  11. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 3# jcchiang
  1. Sub ex()
  2. Dim Rng As Range
  3. With Range("A1:G19")
  4. .UnMerge
  5.    For i = 1 To .Columns.Count
  6.    If Application.CountBlank(.Columns(i)) > 0 Then
  7.      Set Rng = .Columns(i).SpecialCells(xlCellTypeBlanks)
  8.      For Each a In Rng.Areas
  9.        Union(a, a.Offset(-1, 0)).Merge
  10.      Next
  11.     End If
  12.    Next
  13. End With
  14. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 5# jcchiang
  1. Sub ex()
  2. Dim Rng As Range
  3. With Range("A1").CurrentRegion
  4. .UnMerge
  5.    For i = 1 To .Columns.Count
  6.    If Application.CountBlank(.Columns(i)) > 0 Then
  7.      Set Rng = .Columns(i).SpecialCells(xlCellTypeBlanks)
  8.      For Each a In Rng.Areas
  9.        Union(a, a.Offset(-1, 0)).Merge
  10.      Next
  11.     End If
  12.    Next
  13. End With
  14. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 能幹不幹,不如苦幹實幹。
返回列表 上一主題