+ Reply to Thread
Results 1 to 13 of 13

New function recording

Hybrid View

  1. #1
    Registered User
    Join Date
    08-27-2009
    Location
    Gib
    MS-Off Ver
    Excel 2007
    Posts
    62

    Question New function recording

    Hey,
    I have a function, that one of the members in this forum wrote.
    that changes the title of a chart according to the text that is written in a specific cell.
    I added this code to a module:
    Function A_ChangeChartTitle(CNameD, titleA)
    ActiveSheet.ChartObjects(CNameD).Activate
    With ActiveChart
    .HasTitle = True
    .ChartTitle.Text = titleA
    End With
    A_ChangeChartTitle = "Function - Chart Title"
    End Function
    and I was able to use it in the excel- worked fine.
    I tryed to record it , but only once I succeeded in recording it and I got this code:
      Range("G5").Select
        ActiveCell.FormulaR1C1 = "New Title"
        Range("G3").Select
        ActiveCell.FormulaR1C1 = "=A_ChangeChartTitle()"
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.ChartTitle.Select
        Range("G3").Select
        ActiveCell.FormulaR1C1 = "=A_ChangeChartTitle(""Chart 1,G5"")"
    when I tryed to insert it to an existing code I got an error that the value was'nt found.
    Later on I tryed to record it again but it wasn't successfull- there was no code similar to the one I got when I first recorded.

    another thing I noticed is : when I used the function A_ChangeChartTitle stright forward in the excel file:the code in the "insert function" in the excel looked like this:
    =A_ChangeChartTitle("Chart 1",F5)
    but in the code I got while recording- the same one that gave the error - the code looked like that:
    =A_ChangeChartTitle("Chart 1,G5")
    I tryed to change the inverted commas but I got a sintax error.

    Hope you can help me,
    thanks
    Last edited by Abroza; 10-20-2009 at 05:24 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: New function recording

    I don't understand what you are doing. It looks like your Function is changing the Chart title, a function should return a vlue, e.g. the title. A Sub or procdure would normally be used to change an object. Your Function looks like it will always return "Function - Chart Title"

    Attach an example workbook
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: New function recording

    Do you really need code?
    http://www.andypope.info/tips/tip001.htm
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    08-27-2009
    Location
    Gib
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: New function recording

    I tryed the link you gave - of course it worked great, the problem in it as a code, I tryed to record it- it didn't work.
    I want to inser it to an exsiting code so it must be in vba.
    any suggestions?

  5. #5
    Registered User
    Join Date
    08-27-2009
    Location
    Gib
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: New function recording

    this workbook is a good exmple.In cell I1- yellow,I can change the title- and the chart title will be updated, I need this action as a code,
    meaning the code of : inserting the function
    is it clear?

    thanks
    Attached Files Attached Files

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: New function recording

    So code to create the formula, as in the contents of H1?

    activecell.Formula=A_ChangeChartTitle("Chart 1",I1)

  7. #7
    Registered User
    Join Date
    08-27-2009
    Location
    Gib
    MS-Off Ver
    Excel 2007
    Posts
    62

    Question Re: New function recording

    finally !!! it works great!!!
    another thing,
    The text I'm inserting from cell F5 is pretty long. when I wrote titles in the vba, by the code "& Chr(13) & " I was able to display the title in 2 rows. do you know is there a code or function that can split the title in F5 to 2 rows?
    Hope you can help me,
    thanks

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: New function recording

    you can use CHAR(10) in F5 to force a newline.


    ="My" & CHAR(10) & "Title"

  9. #9
    Registered User
    Join Date
    08-27-2009
    Location
    Gib
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: New function recording

    where exactly in the code should I insert it?
    what to write instead of the "title"- the text itself or F5?
    thanks!

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: New function recording

    It is not a change to the code or to the cell formula. It is a change to the contents of the cell with the title text in it.

  11. #11
    Registered User
    Join Date
    08-27-2009
    Location
    Gib
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: New function recording

    works great!
    thanks again...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1