これは、セルに改行が存在するかどうかを調べ、存在する場合は列Bにもそれを追加します。
Sub foo2()
FindString = "/n"
LastRow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row 'find the last row in column A with data
For i = 1 To LastRow
Set Rng = Sheet1.Cells(i, 1).Find(What:=FindString) 'look for the line feed at in this cell
If Not Rng Is Nothing Then 'if found
Sheet1.Cells(i, 2).Value = Sheet1.Cells(i, 2).Value & "/n" 'add line feed to column B
End If
Next i
End Sub
それとも、私はこのような何かがそれを行うだろうと考えているあなたは、文字列「/ N」を探していませんし、あなたがラインフィードを探している場合:
Sub foo2()
LastRow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row 'find the last row in column A with data
For i = 1 To LastRow
Set Rng = Sheet1.Cells(i, 1).Find(What:= vbLf) 'look for the line feed at in this cell
If Not Rng Is Nothing Then 'if found
Sheet1.Cells(i, 2).Value = Sheet1.Cells(i, 2).Value & vbLf 'add line feed to column B
End If
Next i
End Sub
はUPDATE:
Sub foo2()
Dim Str as Variant
LastRow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row 'find the last row in column A with data
For i = 1 To LastRow
Str = Sheet1.Cells(i, 1).Value
If Right(Str, 1) = vbLf Then 'if found
Sheet1.Cells(i, 2).Value = Sheet1.Cells(i, 2).Value & vbLf 'add line feed to column B
End If
Next i
End Sub
のExcelドキュメントを見ることができます。「\ n」で終わり、 '\ n'だけではないセルがあります。 – NetMage
正しいですが、\ nは改行で、実際の文字列 "\ n"ではありません。 –
@Xabier - 迅速なフォローアップの質問をしてもらえますか?期待どおりに動作しますが、改行/フィードが複数あるセルでは機能しません。私は、このマクロで最後の改行(改行後の内容/文字なし)をチェックし、同じセル内に複数行のテキスト(各行を区切る改行)があるので、前の行を無視します。 –