Excel2000 VBA 選択範囲の文字列の置換 [Excel2000 VBA独習]
Excel2000 VBA 選択範囲の文字列の置換
Sub 範囲置換()
'
'testバージョン
'
On Error GoTo owari 'inputboxでキャンセルボタンが押された時の処理のつもり
Dim target As Range
Dim hani, s As Range
Dim str_mae, str_go, x As String
'InputBoxで選択範囲を取得
Set hani = Application.InputBox(Title:="置換する範囲を選択してください!", prompt:="範囲選択文字列の置換", Type:=8)
'置換対象文字
str_mae = Application.InputBox(Title:="置換する文字!", prompt:="置換する文字を入力", Type:=2)
'置換後文字
str_go = Application.InputBox(Title:="置換後の文字!", prompt:="置換後の文字を入力", Type:=2)
'選択範囲 置換
For Each target In hani
target.Value = Replace(target.Value, str_mae, str_go)
Next target
owari:
Set hani = Nothing '解除
End Sub
コメント 0