+ Reply to Thread
Results 1 to 43 of 43

Scroll Bar and Current Value. Min and Max Values

  1. #1
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Scroll Bar and Current Value. Min and Max Values

    Hi folks

    With the scroll bar is it possible to change the current value, min and max values set to input cell references as opposed to setting manually

    ie A1 - this cell i want to set as current value
    B1- SCROLL BAR (linked to C1)

    example

    A1 - data validation list of values (example of values say 100,1000,100000)
    B1 - Scroll Bar (set to C1). problem is i need to set the min max and current values to a manual setting which doesnt work for all the input values as they all have different values, and require different min and max values to make it user friendly.
    So and i want them to be linked to the current values displayed in A1, not manually.
    C1 - Output cell.

    Thanks

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

    Re: Scroll Bar and Current Value. Min and Max Values

    You can not link those values to cells.

    You could however use worksheet event code to determine a change in a particular cell and then update the control.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    Thankyou.

    How can i do this by assigning a macro ?

    Or alternatively can i use an active x control as opposed to a form control ? i thought i saw something applicable on some site and ive forgotten where !

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

    Re: Scroll Bar and Current Value. Min and Max Values

    No, by using the worksheet change event

    right click sheet tab and pick View Code.
    You can then select the worksheet object from the left drop down at top of window.
    The use right drop down to select the change event.

    you can then use code something like this

    Please Login or Register  to view this content.
    Then when any cell content changes the event will fire, The code will test that only A1 was changed and then execute your code to determine and set properties.

  5. #5
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    Here is the simple file



    https://drive.google.com/file/d/0BxH...ew?usp=sharing

    old value scroll new value list
    100 100 100
    1,000
    10,000

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

    Re: Scroll Bar and Current Value. Min and Max Values

    so what determines when the scroll bar min and max changes??

  7. #7
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    thats the problem im trying to solve.

    As default in example the scroll is selected by the user to current 100 (C7). min 50 and max 150.(has to be done manually)

    if i change scenario as in C7 from 100 to say 1,000, then i need the default to change to 1,000, and the min to say 500 and max 1500. (higher current values requires higher min and max values)

    thats the solution im looking for


    thanks

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

    Re: Scroll Bar and Current Value. Min and Max Values

    I added a table of values with corresponding min/max.
    The resulting min/max values are in to named ranges.

    when C7 changes the code should update the scroller.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    great work

    A couple of teaks needed.

    1. Slight code fix

    0 default set to max not "VALUE" (dont need any zero value so disregard this fix)
    10 default set to max not "VALUE"
    50 default set to min not "VALUE"
    100 default set to min not "VALUE"
    1000 default set to min not "VALUE"
    5000 default set to min not "VALUE"

    2. the increments need to be different ie


    Value Min Max Increments
    0 0 10 1
    10 0 20 1
    50 25 100 5
    100 50 150 4
    1000 500 1500 50
    5000 1000 8000 100

    if u can do that 5 stars !

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

    Re: Scroll Bar and Current Value. Min and Max Values

    Have you even tried to make those changes yourself?

  11. #11
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    of course. thats why i sent all the test data above

    the coded says min max and the result is either min or maximum not value which is what i am trying to compute . also i cant see any way to change the incremental change.

    thanks in advance
    Last edited by alive555; 08-05-2015 at 08:26 AM.

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

    Re: Scroll Bar and Current Value. Min and Max Values

    Looking at help on ControlFormat would have shown the other properies than could be altered.
    Even using the macro recorder would have shown you them.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    Thanks this works !

    Sry first time trying macros so getting some probs.

    I tried to add another scroll bar below and when i try to set the new target cell from C7 i get error message ?

    heres my update file

    https://drive.google.com/file/d/0BxH...ew?usp=sharing

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

    Re: Scroll Bar and Current Value. Min and Max Values

    revised code

    Please Login or Register  to view this content.
    There are 2 new named ranges on sheet2, which define all settings for a given control.

    You code did not work for 2 reasons first the cell being checked for change was not the actual cell changing.
    And now the cell that was changing contains a formula, which does not fire the change event, so you need to check the cell that drives the formula.

    The event code checks for a change in either of the 2 selection cells and then updates the appropriate control with the relevant parameters.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    Hi andy

    Thanks, downloaded and tested. Appears to be working well ! well done sir

    Last question

    1. how do i add alter the code so as i can add additional scroll bars . ie now i have scroill bar 1 and 2, How do i add scroll bar 3,4,5,6, etc

    2. if i want to put this into my workbook do i paste it in the page i have the scroll bar(s) i have already created , or is there other code fixes required to link the control to the scroll bar(s), and sheet 2 in this case where the cells are referenced ?

    sorry have to ask newbie questions

    great work

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

    Re: Scroll Bar and Current Value. Min and Max Values

    You need to expand the event code to handle each scrollbar and changing cell.
    If each scroll bar has it's own set of parameters then you also need to add named ranges on the other sheet for each set.

    If you copy sheets the code should move too

  17. #17
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    https://drive.google.com/file/d/0BxH...ew?usp=sharing

    attempted that fix now getting error in min value .


    Dim CtlFmt As ControlFormat
    Dim ScrollData As Range

    If Target.Cells.Count = 1 Then
    If Not Intersect(Target, Range("B3")) Is Nothing Then
    Set CtlFmt = Target.Parent.Shapes("Scroll Bar 2").ControlFormat
    Set ScrollData = [SCROLL_INFO_1]
    ElseIf Not Intersect(Target, Range("B6")) Is Nothing Then
    Set CtlFmt = Target.Parent.Shapes("Scroll Bar 4").ControlFormat
    Set ScrollData = [SCROLL_INFO_2]
    ElseIf Not Intersect(Target, Range("B9")) Is Nothing Then
    Set CtlFmt = Target.Parent.Shapes("Scroll Bar 6").ControlFormat
    Set ScrollData = [SCROLL_INFO_3]
    End If

    If Not ScrollData Is Nothing Then
    With CtlFmt
    .Min = ScrollData.Cells(2, 1)
    .Max = ScrollData.Cells(3, 1)
    .SmallChange = ScrollData.Cells(4, 1)
    .LargeChange = ScrollData.Cells(5, 1)
    .Value = ScrollData.Cells(6, 1)
    End With
    End If
    End If
    End Sub

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

    Re: Scroll Bar and Current Value. Min and Max Values

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)


    Have you tried doing it manually? The error box will tell you the problem.

    The usual way around the scroller limits is to use a helper cell and factor the resulting value in some way

  19. #19
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim CtlFmt As ControlFormat
    Dim ScrollData As Range

    If Target.Cells.Count = 1 Then
    If Not Intersect(Target, Range("B3")) Is Nothing Then
    Set CtlFmt = Target.Parent.Shapes("Scroll Bar 2").ControlFormat
    Set ScrollData = [SCROLL_INFO_1]
    ElseIf Not Intersect(Target, Range("B6")) Is Nothing Then
    Set CtlFmt = Target.Parent.Shapes("Scroll Bar 4").ControlFormat
    Set ScrollData = [SCROLL_INFO_2]
    ElseIf Not Intersect(Target, Range("B9")) Is Nothing Then
    Set CtlFmt = Target.Parent.Shapes("Scroll Bar 6").ControlFormat
    Set ScrollData = [SCROLL_INFO_3]
    End If

    If Not ScrollData Is Nothing Then
    With CtlFmt
    .Min = ScrollData.Cells(2, 1)
    .Max = ScrollData.Cells(3, 1)
    .SmallChange = ScrollData.Cells(4, 1)
    .LargeChange = ScrollData.Cells(5, 1)
    .Value = ScrollData.Cells(6, 1)
    End With
    End If
    End If
    End Sub
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    End Sub


    the error box highlights

    .Min = ScrollData.Cells(2, 1)

    i have no idea what are cells 2,1 ? and i changed both cells to 1,2,3,4 and all variations still get error.

    Anyone else ?
    Last edited by alive555; 08-07-2015 at 06:57 AM.

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

    Re: Scroll Bar and Current Value. Min and Max Values

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)


    Did you do as I suggested and try setting the values manually?

    1097467.png

  21. #21
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    Please Login or Register  to view this content.
    the error box highlights

    .Min = ScrollData.Cells(2, 1)

    i have no idea what are cells 2,1 ? and i changed both cells to 1,2,3,4 and all variations still get error.

    Anyone else ?

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

    Re: Scroll Bar and Current Value. Min and Max Values

    I will give you time to re read my previous post

  23. #23
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    you cant get any maximum number in any of the cells over 30,000.

    must be solution. use if and factor up and factor down ?

    my values go up to 1 million

    cheese
    Last edited by alive555; 08-07-2015 at 07:11 AM.

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

    Re: Scroll Bar and Current Value. Min and Max Values

    the control will only accept positive Integer values upto 30000.

    You would need to redesign sheet1 to work with acceptable values.
    So new formula in F9 =E9*10

    And divide all the value in sheet2!J24:J29 by 10

  25. #25
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    Thx -

    Ive just done as suggested. First scroll bar works next 2 dont. No idea whats going wrong.

    https://drive.google.com/file/d/0BxH...ew?usp=sharing

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

    Re: Scroll Bar and Current Value. Min and Max Values

    Your VLOOKUP formula needs to be updated to use the correct value to be compared in first column

    J15: =VLOOKUP(Sheet1!C6/L13,B14:G19,2)/L13

    you need to factor that down too. repeat for all formula in that table

  27. #27
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    Thanks Andy that worked.

    Attached 2 files. Original file now working

    https://drive.google.com/file/d/0BxH...ew?usp=sharing

    and my own file where i pasted the code and tried to amend.

    https://drive.google.com/file/d/0BxH...ew?usp=sharing

    Clearly its not right yet can u pls have a quick butchers pls ?

    thankyou

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

    Re: Scroll Bar and Current Value. Min and Max Values

    named range scroll_info_3 is not the correct area.
    the contents of scroll_info_3 are incorrect as they exceed controls limits.

    the event code has not be changed to match the change in you sheet layout.

    Please Login or Register  to view this content.

  29. #29
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    thanks andy ill have a look in the morning

  30. #30
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    Corrected value limit error
    Corrected scroll value
    Attempted to change the event code . scroll bar not functioning. Suspect thats wrong, tried various options failed.

    https://drive.google.com/file/d/0BxH...ew?usp=sharing

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

    Re: Scroll Bar and Current Value. Min and Max Values

    your link generates error.

    Why not use the forum upload, like everybody else?

  32. #32
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    heres the file

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

    Re: Scroll Bar and Current Value. Min and Max Values

    all of the code references to the named ranges were wrong, as it appears you altered the size those ranges

    Please Login or Register  to view this content.

  34. #34
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    i pretty sure i did not change the references ! I note the above is different from the previous range. This one works after a quite a bit of jigging with the calculations . thanks,

    When i try to add scroll bar 4 i dont know what is the correct Scroll Bar number (no idea how this is referenced as its not referenced anywhere i can find in the spreadsheet/named range/lookuptable)

    ie scroll bar ("Scroll Bar 2") = scroll bar 1 in B4
    ("Scroll Bar 4") = scroll bar 2 in B5
    ("Scroll Bar 9") = scroll bar 3 in B6
    ("Scroll Bar ?") = scroll bar 4 in B7
    (and next one will be ?) = scroll bar 5 in B8. etc etc

    im planning to add another 10 or so......
    Attached Files Attached Files
    Last edited by alive555; 08-12-2015 at 03:06 AM.

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

    Re: Scroll Bar and Current Value. Min and Max Values

    When you add a control the name is displayed in the Name Box to the Left of the formula bar. Or you can use ALT+F10 to display selection task pane.
    1097467_pic1.png

    Someone did change the contents of the named ranges.
    Originally it was values in J4:J9

    Value 50
    Min 25
    Max 75
    Small 5
    Large 10
    Value 50

    and now the it's values in L4:L8
    Min 0
    Max 2
    Increment 0
    Page 10
    St. Value 1

    The location is not a problem as the code works relative to named range. The problem is the row position within the named range.
    So the MIN value was originally in row 2. The new layout it's in row 1. Without the adjustment to the code in the Change event the wrong values were being used.

  36. #36
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    thanks

    If you recall those named ranges were changed 4 iterations ago ! As mentioned before its a completely different file.

    Can i ask why the control name does not show up in the name manager only accessed by highlighting the scroll bar or alt f10 ?

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

    Re: Scroll Bar and Current Value. Min and Max Values

    As the help says, "Use the Name Manager dialog box to work with all of the defined names and table names in the workbook". It does not do shapes or controls.

    In terms of where the controls name appears it is the same as any other shape on the spread sheet.

  38. #38
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    ok after a load more messing around with the limits of the scroll bar there is a max limit of 60,000,000

    as attached , no idea how to improve this other than using formula ie. if value between 100,000 and 1,000 then x and 1,000,000 and 10,000,000 then y etc , which i dont how yet to do . working on that next !
    Attached Files Attached Files

  39. #39
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    now tested the hell out of it and getting errors !!

    As Attached.

    M30 in sheet 3 is one problem. ....

    Think the range is incorrect on scroll bar 4 and thats the issue . Can u resolve pls ?
    Attached Files Attached Files

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

    Re: Scroll Bar and Current Value. Min and Max Values

    In your workbook it says "< CHANGE TO 1 GET ERROR ". You would get a vlookup result of #N/A if you look for a value that does not exist.

    Why would you set that cell to 1?

  41. #41
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    Removed the factoring value completely and getting more errors !
    the range has to be wrong ?
    Attached Files Attached Files

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

    Re: Scroll Bar and Current Value. Min and Max Values

    Try changing the formula from VLOOKUP to and INDEX formula.

    Currently you a looking up based on the value whereas the information is based on company selected. So instead use Match to get the Company
    position within the table and use those values.

    You still need to incorporate the factoring values on the final output value.
    Attached Files Attached Files

  43. #43
    Registered User
    Join Date
    04-18-2011
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Scroll Bar and Current Value. Min and Max Values

    well done Andy

    At last solved!

+ 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. [SOLVED] Set PivotTable Filter to Current Day, Current Week, Current Month, or Current Year
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2014, 08:31 AM
  2. [SOLVED] copy and paste in current active cell, and need current date then scroll down 140 lines
    By vengatvj in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-04-2013, 03:40 AM
  3. [SOLVED] Frozen panes, using macro to add entries. want the sheet to scroll to the current row.
    By emilyloz in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-12-2013, 11:15 AM
  4. Scroll bar (Form Control) - Resetting the scroll bar to particular values
    By Vishb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-29-2011, 04:10 AM
  5. scroll along row looking for values?
    By newdude in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-27-2007, 01:26 AM
  6. Replies: 1
    Last Post: 04-18-2006, 11:40 AM
  7. [SOLVED] Replacing Linked Cell Values w/ Current Values
    By TomCat in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-10-2006, 07:25 AM

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