Excel Merge Cells
3002 단어 Excel
Sub Macro1()
Application .ScreenUpdating = False
Application .DisplayAlerts = False '
Dim rng As Range
Set rng = Cells(1 , 1 ) ' A1
For i = 1 To Range("a65536" ).End (xlUp).Row + 1
If Trim (Cells(i, 1 )) = "" Then '
Set rng = Union(rng, Cells(i, 1 ))
Else
rng.Merge: Set rng = Cells(i, 1 )
End If
Next i
Application .ScreenUpdating = True
Application .DisplayAlerts = True
End Sub
1. Determine whether the cell is included in the merged cell. The MergeCells property can be used to determine whether a cell is included in a merged cell. For example, if A1:B2 is merged into a merged cell, then: Range("A1").MergeCells will return True!
2. Get the merged area containing the specified cells. The MergeArea property can obtain the merged area containing the specified cells, such as: A1:B2 is merged into a merged cell, then: Range("A1").MergeArea.Address will return $A$1:$B$2.
3. Merge replication. When merging cells, we often encounter that in the merged cell range, there are multiple cells with content, and when merging cells, it will prompt that only the data in the upper left corner can be retained. After the content is merged, all the content is also merged into the merged cell, you can use this custom macro to complete
Sub 2()
Dim c As Range, r As Range, i As Integer, x, n As New Collection, Str As String
With Sheet2
.Range(.[A2], .[C2].End(xlDown)).ClearContents
Set c = [A2]
Set r = .[A2]
End With
Do While c <> ""
x = Split(c.Offset(0, 2), "/") ' C
For i = 0 To UBound(x)
If x(i) <> "" Then
On Error Resume Next
n.Add x(i), CStr(x(i))
On Error GoTo 0
End If
Next
If c <> c.Offset(1, 0) Then '
For i = 1 To n.Count
Str = Str & IIf(Str = "", "", "、") & n.Item(1) ' ,
n.Remove (1)
Next
r = c '
r.Offset(0, 1) = c.Offset(0, 1)
r.Offset(0, 2) = Str
Str = ""
Set r = r.Offset(1, 0) '
End If
Set c = c.Offset(1, 0) '
Loop
End Sub
Fill blank cells
Range("P7:P13").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=R[-1]C"
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Excel Grep toolExcel Grep tool ■히나가타 ■ 시트 구성 ExcelGrep.cls...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.