2009-08-18 79 views
1

在Excel中,如果它們包含換行符(alt + Enter),我希望能夠自動將一個單元格分成兩個或多個單元格。我如何做到這一點,以便它將細胞分成新的細胞下方的行?如果它包含一個換行符,打破一個單元格

+0

我不能幫不論,但誰知道Excel的人來說,它可能會幫助,如果你指定你如何與它接口。 COM? – 2009-08-18 05:52:42

回答

1
Sub MakeTwoCellsForCellHavingLF() 
Dim currentCellValue As String, LFFoundAt As Integer 

currentCellValue = ActiveCell.Value 
LFFoundAt = InStr(1, currentCellValue, vbLf) 

If LFFoundAt <> 0 Then 
    ActiveCell.Value = Left(currentCellValue, LFFoundAt - 1) 
    ActiveCell.Offset(1).Value = Mid(currentCellValue, LFFoundAt + 1) 
End If 
End Sub 
0

假設您的數據在A1中。

A2應包括(請原諒,並刪除C風格的註釋。):

=FIND(CHAR(10),A1) // Location of CHAR(10), your newline. 

ASCII 10意味着換行符。隱藏行2

A3應該包含:

=IF(
    NOT(ISERR(A2)), // Make sure there is a newline 
    LEFT(A1, A2-1), // Everything up to the newline 
    A1    // If there's no newline, original string 
    ) 

A4應該包含:

=IF(
    NOT(ISERR(A2)),  // Make sure there is a newline 
    RIGHT(A1, LEN(A1)-A2), // Everything after the newline 
    ""      // If there's no newline, nothing 
    ) 
相關問題