| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

「Excel VBA すべてのシートに対して一括置換」の版間の差分

提供: MyMemoWiki
ナビゲーションに移動 検索に移動
1行目: 1行目:
 
==Excel VBA すべてのシートに対して一括置換==
 
==Excel VBA すべてのシートに対して一括置換==
[[Excel]][[Excel VBA]]
+
[[Excel]] | [[Excel VBA]] |
  
 
{{amazon|4798122084}}
 
{{amazon|4798122084}}

2020年2月15日 (土) 08:35時点における版

Excel VBA すべてのシートに対して一括置換

Excel | Excel VBA |

すべてのシートに対して一括置換する

  1. Sub AllReplace()
  2. Dim f As String
  3. Dim t As String
  4. Dim i As Integer
  5. Dim sht As Excel.Worksheet
  6. f = InputBox("置換対象文字列を入力してください")
  7. If Trim$(f) <> "" Then
  8. t = InputBox("置換後文字列を入力してください")
  9. End If
  10.  
  11. If Trim$(t) = "" Then
  12. Exit Sub
  13. End If
  14. For i = 1 To ActiveWorkbook.Sheets.Count
  15. Set sht = ActiveWorkbook.Sheets(i)
  16. If sht.Name = f Then
  17. sht.Name = t
  18. End If
  19.  
  20. sht.Cells.Replace What:=f, Replacement:=t, LookAt:= _
  21. xlPart, SearchOrder:=xlByRows, MatchCase:=False, MatchByte:=False
  22. Next
  23.  
  24. Call MsgBox("完了")
  25. End Sub