Results 1 to 2 of 2

Thread: Find Replace in Excel Charts

  1. #1

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Find Replace in Excel Charts

    I want to be able to find and replace in the axis titles of charts.

    I made a chart with the x axis title "Freq (GHz)"
    I then copied and pasted the chart many times and just modified the source data.
    Now I realise I need the x axis title to say "Frequency (GHz)"

    Anyone want to help me out with a macro to find and replace freq with frequency?

    I think its going to be something like this
    VB Code:
    1. 'Loop through sheets
    2. 'Is it a chart?
    3. 'If so what is the axis title
    4. 'Replace it?
    5.    ActiveChart.Axes(xlValue).AxisTitle.Select
    6.     Selection.Characters.Text = "Frequency (GHz)"
    I'm quite tired today and am having difficulty working it through.
    2 cans of Red Bull and I'm still drooping!
    Any help much appreciated.

  2. #2

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    After a nice curry for lunch and a bit of help from Jon Peltier (Excel MVP) I have come up with this
    VB Code:
    1. Dim Cht As Chart
    2.    Dim strFind As String
    3.    Dim strReplace As String
    4.    
    5.    strFind = "Freq (GHz)"
    6.    strReplace = "Frequency (GHz)"
    7.  
    8.  
    9. 'Loop through charts
    10.    For Each Cht In ActiveWorkbook.charts
    11.      Cht.Axes(xlCategory).AxisTitle.Characters.Text = _
    12.        WorksheetFunction.Substitute(Cht.Axes(xlCategory).AxisTitle.Characters.Text, strFind, strReplace)
    13.    Next
    Unfortunately in its current state it doesnt check for whole words
    ie if you changed "Freq" to "Frequency" and a chart already had
    the word "Frequency" you would end up with FreqFrequency

    It would probably look better in a form as well
    And some highlighting and a "Do you want to replace this?" option
    But I can't be arsed at the moment

    If you are enthusiastic I would appreciate you doing it and posting it back here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width