+ Reply to Thread
Results 1 to 12 of 12

assign different chart line type under different condition with vba

  1. #1
    Forum Contributor
    Join Date
    09-22-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    184

    assign different chart line type under different condition with vba

    Hi all,

    As above, there are only two type of line and condition to consider here.

    When condition 1 is met, the line is solid and condition 2, the line is dash.

    Want to create a vba which link to excel cell when the condition are met, the line change itself.

    There is Private Sub Worksheet_Change(ByVal Target As Range) in my file. No sure if this is the place to put the macro. Just let you know.

    Here is the two macro I get from the record macro:
    Please Login or Register  to view this content.
    Appreciated any help given.

  2. #2
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: assign different chart line type under different condition with vba

    Hello DavidRoger

    Can you tell what values that cell can have (ie. 1 or 2, Solid or Dash etc.)

  3. #3
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,449

    Re: assign different chart line type under different condition with vba

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    09-22-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    184

    Smile Re: assign different chart line type under different condition with vba

    Hi all,

    I think I need to rephrase my message. Found something interesting after going through my vba.

    Below is the code I use for .values, xvalues, line weight, name, and other:


    Please Login or Register  to view this content.


    Below code is the amended code I get from the above code. However this will not work because Range ("A100").value is for number not for text. Tried replacing with [A100] but not working too. What else can be use in the ??? below?

    Please Login or Register  to view this content.
    All help is appreciated and Happy New Year .

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

    Re: assign different chart line type under different condition with vba

    Please Login or Register  to view this content.
    msoLineSysDash and msoLineSolid are VBA constants that have numeric values. The above checks for text match and then uses the constant.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Contributor
    Join Date
    09-22-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    184

    Re: assign different chart line type under different condition with vba

    Quote Originally Posted by Andy Pope View Post
    Please Login or Register  to view this content.
    msoLineSysDash and msoLineSolid are VBA constants that have numeric values. The above checks for text match and then uses the constant.
    Hi Andy,

    This is what I do. I copy and paste the code into my vba. Enter cell A100 with msoLineSysDash or msoLineSolid. It's work.

    I am prefer sure that not what you mean.

    Other that than I tried

    1) to change the line type manual, but nothing happen to A100.

    2) And tried to insert A100 with number 1 - 100, also nothing happen.

    Please confirm "The above checks for text match and then uses the constant".

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

    Re: assign different chart line type under different condition with vba

    Yes, just make sure the references to range and chart object are correct for your file.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    09-22-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    184

    Re: assign different chart line type under different condition with vba

    Quote Originally Posted by Andy Pope View Post
    Yes, just make sure the references to range and chart object are correct for your file.
    Thanks.

    Wish you good blessing in 2014.

  9. #9
    Forum Contributor
    Join Date
    09-22-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    184

    Re: assign different chart line type under different condition with vba

    When there are more than two conditions, in what way can the code be amended?

  10. #10
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,449

    Re: assign different chart line type under different condition with vba

    use select case or a 2nd Iif (but here it's twice the same condition and change the x in a valid expression)
    Please Login or Register  to view this content.

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

    Re: assign different chart line type under different condition with vba

    you can use a SELECT CASE test

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    09-22-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    184

    Re: assign different chart line type under different condition with vba

    Thanks both.

    IIF and SELECT case is good.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Changing line cap type for X-Y chart
    By michch in forum Excel Charting & Pivots
    Replies: 13
    Last Post: 12-20-2016, 03:11 PM
  2. Help creating special type of line chart
    By zeospeed in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 09-01-2013, 09:55 AM
  3. [SOLVED] Chart Lengend to show marker style on hidden line - Line chart
    By etaf in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 08-22-2013, 05:19 PM
  4. How to apply the custom chart type: "Line - Column on 2 Axes"
    By talrs in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-20-2006, 04:25 AM
  5. Adding a line Chart Type to a stacked-clustered Chart Type
    By Debbie in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 01-05-2005, 08:06 PM

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