メインコンテンツへスキップ

Excelでグラフのタイトルのテキストを見つけて置き換える方法は?

グラフはExcelで非常に便利であり、グラフを識別するためにいくつかのタイトルを付けることがよくあります。 しかし、複数のグラフ内のグラフタイトルのテキスト値を見つけて置き換えようとしましたか? 今日は、複数のグラフタイルで特定のテキストを見つけて、Excelで他の値に置き換える方法について説明します。

Excelのグラフタイトルのテキストを検索してVBAコードに置き換えます


矢印青い右バブル Excelのグラフタイトルのテキストを検索してVBAコードに置き換えます

次のスクリーンショットに示すようなグラフを含むワークシートがあり、すべてのグラフタイトル内のテキストをXNUMX月からXNUMX月に置き換えたいとします。 もちろん、手動でXNUMXつずつ変更することもできますが、複数のグラフがある場合は時間がかかります。 したがって、ここでは、次のVBAコードがこのタスクの処理に役立ちます。</ p>

doc-replace-chart-titles1

1。 検索して置き換えるチャートがタイトルに含まれているワークシートをアクティブにします。

2。 を押し続けます Alt + F11 キー、そしてそれは開きます Microsoft Visual Basic forApplicationsウィンドウ.

3に設定します。 OK をクリックします。 インセット > モジュール、次のコードをに貼り付けます モジュールウィンドウ.

VBAコード:アクティブなワークシート内のグラフタイトルのテキストを検索して置換します

Sub ChartLabelReplace()
'Update 20140603
Dim xWs As Worksheet
Dim xFindStr As String
Dim xReplace As String
xFindStr = Application.InputBox("Find:", xTitleId, "", Type:=2)
xReplace = Application.InputBox("Replace:", xTitleId, "", Type:=2)
Set xWs = Application.ActiveSheet
For Each ch In xWs.ChartObjects
    If ch.Chart.HasTitle Then
        ch.Chart.ChartTitle.Text = VBA.Replace(ch.Chart.ChartTitle.Text, xFindStr, xReplace, 1)
    End If
Next
End Sub

4。 次に、 F5 このコードを実行するためのキーを押すと、置き換えたい古いテキストを入力するように促すプロンプトボックスが表示されます。スクリーンショットを参照してください。

doc-replace-chart-titles1

5。 そして、 OK ボタンをクリックすると、別のプロンプトボックスが表示されます。古いテキスト値を置き換える新しいテキスト値を入力する必要があります。スクリーンショットを参照してください。

doc-replace-chart-titles1

6。 クリックしてください OK プロンプトボックスを閉じると、次のスクリーンショットに示すように、現在のワークシートで古いテキストが一度にニュースに置き換えられます。

doc-replace-chart-titles1

Note:ブック内のすべてのワークシートでグラフのタイトルのテキスト値を見つけて置き換える必要がある場合は、次のVBAコードを適用する必要があります:(手順は上記と同じです)

VBAコード:すべてのワークシート内のグラフタイトルのテキストを検索して置換します

Sub ChartLabelReplaceAllWorksheet()
'Update 20140603
Dim xFindStr As String
Dim xReplace As String
xFindStr = Application.InputBox("Find:", xTitleId, "", Type:=2)
xReplace = Application.InputBox("Replace:", xTitleId, "", Type:=2)
For Each sh In Worksheets
    For Each ch In sh.ChartObjects
        If ch.Chart.HasTitle Then
            ch.Chart.ChartTitle.Text = VBA.Replace(ch.Chart.ChartTitle.Text, xFindStr, xReplace, 1)
        End If
    Next
Next
End Sub

関連記事:

Excelでコメント内のテキストを見つけて置き換える方法は?

Excelの複数のテキストボックスで特定のテキストを見つけて置き換える方法は?

Excelで一度に複数のハイパーリンクパスを変更するにはどうすればよいですか?

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト 工具 (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 工具 (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 工具 (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット 工具 (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!

 

Comments (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Just want to say thanks for this. Saved me hours of time.
This comment was minimized by the moderator on the site
I want to do this for text in the legend and axis labels as well. What's the VBA name for the Legend? I tried to edit the module by replacing "ChartTitle" with "Legend" "LegendEntry" "ChartLegend" none work.
This comment was minimized by the moderator on the site
Some of my chart titles contain multiple font sizes. When I run the macro above, it converts all of the fonts to the same size and I have to go back through and manually re-size them. Is there a way to modify the VBA code so that it maintains the original font sizes? (I'm still a VBA newb, so any help would be appreciated!)
This comment was minimized by the moderator on the site
Thank you!!! It helped me so much!!!
This comment was minimized by the moderator on the site
This one works for me, because otherwise the variables are not declared : Sub ChartLabelReplace() 'Update 20141017 Dim xFindStr As String Dim xReplace As String Dim ws As Worksheet Dim ch As ChartObject xFindStr = InputBox("Find:") xReplace = InputBox("Replace:") For Each ws In Worksheets For Each ch In ws.ChartObjects If ch.Chart.HasTitle Then ch.Chart.ChartTitle.Text = VBA.Replace(ch.Chart.ChartTitle.Text, xFindStr, xReplace, 1) End If Next Next End Sub
This comment was minimized by the moderator on the site
How does one change the VBA macro to only apply the change to selected charts (and not all the charts on the worksheet)?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations