+ Reply to Thread
Results 1 to 14 of 14

VBA How to use the InputBox to create charts

  1. #1
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    VBA How to use the InputBox to create charts

    How do you use the InputBox to set ranges for charts?

    For example, to create a chart, I use:
    Please Login or Register  to view this content.
    This code lets you select a range of cells to highlight yellow:
    https://www.thespreadsheetguru.com/s...with-inputbox/
    Please Login or Register  to view this content.
    And this code lets you select the chart source data for the active chart:
    https://peltiertech.com/assign-chart...ries-with-vba/
    Please Login or Register  to view this content.
    How would you build the create chart macro with the InputBox? So that you can select:
    Please Login or Register  to view this content.


    Thank you very much!
    Last edited by briskie; 04-17-2024 at 10:29 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,615

    Re: VBA How to use the InputBox for any routine using ranges

    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,530

    Re: VBA How to use the InputBox for any routine using ranges

    Just as information. You can use your mouse to select the range with the code from protonLeah.
    Experience trumps academics every day of the week and twice on Sunday.

  4. #4
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA How to use the InputBox to create charts

    Wow! Awesome!
    Last edited by briskie; 04-18-2024 at 02:50 PM.

  5. #5
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA How to use the InputBox to create charts

    Selecting a range for the chart area works the same way:
    Please Login or Register  to view this content.
    So now, two InputBoxes appear one after another:

    1. "Enter data range"
    2. "Enter chart range"

    You can select the data range as well as the chart range using the mouse.

    Wow!
    Last edited by briskie; 04-18-2024 at 02:50 PM.

  6. #6
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA How to use the InputBox to create charts

    Selecting a range with the series name does not seem to work the same way:

    Please Login or Register  to view this content.
    A third InputBox appears right after the first two, yes. You can select a range, yes. But somehow it is not being "saved".
    Last edited by briskie; 04-18-2024 at 02:50 PM.

  7. #7
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA How to use the InputBox to create charts

    To set the series name to a cell reference I use:
    Please Login or Register  to view this content.
    https://www.excelforum.com/excel-pro...ml#post5937293

    And to set the chart name I use:
    Please Login or Register  to view this content.
    Last edited by briskie; 04-18-2024 at 02:50 PM.

  8. #8
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA How to use the InputBox to create charts

    This code lets you select a range with the series name:
    https://peltiertech.com/assign-chart...ries-with-vba/
    Please Login or Register  to view this content.
    So I tried:
    Please Login or Register  to view this content.
    Doesn't work.

    Last edited by briskie; 04-18-2024 at 02:51 PM.

  9. #9
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    252

    Re: VBA How to use the InputBox for any routine using ranges

    That's because you've left the Type as "8", which is for selecting ranges. You should leave it to default for strings.

  10. #10
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA How to use the InputBox to create charts

    I'm trying not to enter the name as text. I'm trying to select a cell range.
    Last edited by briskie; 04-18-2024 at 02:51 PM.

  11. #11
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA How to use the InputBox to create charts

    Selecting a range for the chart name works the same way as "data range" and "chart range":
    Please Login or Register  to view this content.
    You get another InputBox to select a cell or range you want to use as the chart name.
    Last edited by briskie; 04-18-2024 at 02:51 PM.

  12. #12
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA How to use the InputBox to create charts

    Ok. So this works for chart title and chart name:
    Please Login or Register  to view this content.
    Last edited by briskie; 04-17-2024 at 10:55 PM.

  13. #13
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA How to use the InputBox to create charts

    The only thing I can't get to work is the series name:
    Please Login or Register  to view this content.
    Last edited by briskie; 04-18-2024 at 02:52 PM.

  14. #14
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA How to use the InputBox to create charts

    In order for the series name to be highlighted with the red frame, your data layout should ideally be:

    ______________CategoryLabels

    SeriesName____ DataValues

    Otherwise, you will only see the purple frame highlighting the Category Labels and the blue frame highlighting the DataValues.
    The solution is to set the series name to a cell reference by using:
    Please Login or Register  to view this content.
    You set the range, e.g.("B4") in your code and you're good to go. The series name is now highlighted with the red frame.
    You will also see, that the "Name" in the "Select Data Source" box is now filled accordingly, e.g. "=Sheet1!$B$4".
    https://www.excelforum.com/excel-pro...ml#post5937293

    This seems to be the same case when using an InputBox, this does the trick:
    https://superuser.com/questions/9479...excel-2010-vba
    Please Login or Register  to view this content.
    Finally, everything works:
    Please Login or Register  to view this content.
    1/5 Select your chart data range
    2/5 Select your chart range
    3/5 Select your series name range
    4/5 Enter your chart name
    5/5 Enter your chart title

    Thank you very much protonLeah!

    Attached Images Attached Images

+ 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. quick question regarding setting ranges mid-routine
    By terriertrip in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-03-2020, 01:47 PM
  2. Modify routine to add / delete sheets with names from input ranges
    By cvmelkus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2015, 03:31 PM
  3. [SOLVED] Inputbox defining the Pathname is only opening the first workbook and not running routine
    By graym463 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-19-2015, 08:41 AM
  4. How to modify routine to add / delete / rename tabs from input ranges
    By cvmelkus in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-17-2015, 03:08 PM
  5. [SOLVED] Passing Multiple ranges to Sub Routine
    By madhatter40 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-20-2013, 04:19 PM
  6. Replies: 2
    Last Post: 09-15-2009, 10:33 AM
  7. VBA code for InputBox vbCancel to run the routine
    By Glenn P in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-21-2005, 06:24 PM

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