excelvba 文字列の変更 削除
Message#4 2015年2月5日(木)14時06分 From: クロワッサン |
VBAの中では改行は「vbLf」で扱えます。 置換で"、"&vbLfを”、”に置換などしていく手もありますが、改行のみの行の扱いが厄介ですね。 セルの中で"、"&vbLfなどを”、■”などに一旦置換し、残ったvbLfを”、”に置き換えてから最後に"■"をvbLfに戻す、という手もあるかな。 とりあえずアクティブセルに対して働くマクロで、ベタに組んでみました。 セルの内容は文字列でしょうから、instrでvbLfの位置を検索し、それのひとつ前の文字で判定してvbLfを""に置換ています。 〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜 Sub Macro1() ' With ActiveCell cnt = 0 Do n = InStr(n + 1, ActiveCell, vbLf) If n = 0 Then Exit Do Else If Mid(ActiveCell, n - 1, 1) = "、" Then ActiveCell.Characters(n, 1).Text = "" Else: If Mid(ActiveCell, n - 1, 1) = "、" Then ActiveCell.Characters(n, 1).Text = "" Else: If Mid(ActiveCell, n - 1, 1) = "。" Then ActiveCell.Characters(n, 1).Text = "" Else: If Mid(ActiveCell, n - 1, 1) = "。" Then ActiveCell.Characters(n, 1).Text = "" Else: If Mid(ActiveCell, n - 1, 1) = "." Then ActiveCell.Characters(n, 1).Text = "" Else: If Mid(ActiveCell, n - 1, 1) = "," Then ActiveCell.Characters(n, 1).Text = "" Else: ActiveCell.Characters(n, 1).Text = "、" End If End If End If End If End If End If cnt = cnt + 1 End If Loop End With End Sub |
上のメッセージを削除します。
よければパスワードを入力し、削除ボタンをクリックしてください。