Results 1 to 8 of 8

Thread: Custom Spin Button Based On Values Passed From Array

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Preeti Verma's Avatar
    Join Date
    May 2012
    Posts
    5
    Rep Power
    0
    @ExcelFox
    @Zack Barresse


    Thanks for your concise solution & quick response.

    I needed two custom shapes for my problem which actually involved Java Swing API simulation on Excel using VBA coding.
    Last edited by Preeti Verma; 05-22-2012 at 04:05 PM. Reason: Added functionality to alternative II.

  2. #2
    Junior Member Preeti Verma's Avatar
    Join Date
    May 2012
    Posts
    5
    Rep Power
    0

    CustomSpinControlVBA

    Quote Originally Posted by Preeti Verma View Post
    @ExcelFox
    @Zack Barresse


    Thanks for your concise solution & quick response.

    I needed two custom shapes for my problem which actually involved Java Swing API simulation on Excel using VBA coding.

    Thanks again!





    @Zack Barresse

    I have modified your code a bit to make spin truly circular as under:

    Option Explicit
    Dim oBtnClk As Shape
    Dim WS As Worksheet
    Dim rCell As Range
    Dim arr() As String
    Dim iPos As Long
    Const sArr As String = "Txt1, Txt2, Txt3, Txt4, Txt5, Txt6, Txt7, Txt8, Txt9, Txt10, Txt11, Txt12"
    Const sTargetSheet As String = "Sheet1"
    Const sTargetCell As String = "E4"

    Sub Increase()
    Set oBtnClk = Nothing
    Set WS = Worksheets(sTargetSheet)
    Set rCell = WS.Range(sTargetCell)
    On Error Resume Next
    Set oBtnClk = WS.Shapes(Application.Caller)
    arr = Split(sArr, ", ")
    iPos = WorksheetFunction.Match(rCell.Value, arr(), 0)
    On Error GoTo 0
    If oBtnClk Is Nothing Then Exit Sub
    If iPos = 0 Then
    rCell.Value = arr(LBound(arr))
    Exit Sub
    End If
    '**************************
    If iPos - 1 = UBound(arr) Then
    iPos = LBound(arr)
    End If
    rCell.Value = arr(iPos)
    '**************************
    End Sub

    Sub Decrease()
    Set oBtnClk = Nothing
    Set WS = Worksheets(sTargetSheet)
    Set rCell = WS.Range(sTargetCell)
    On Error Resume Next
    Set oBtnClk = WS.Shapes(Application.Caller)
    arr = Split(sArr, ", ")
    iPos = WorksheetFunction.Match(rCell.Value, arr(), 0)
    On Error GoTo 0
    If oBtnClk Is Nothing Then Exit Sub
    If iPos = 0 Then
    'not set yet
    rCell.Value = arr(LBound(arr))
    Exit Sub
    End If
    '*****************************
    If iPos - 1 = LBound(arr) Then
    iPos = UBound(arr) + 2
    End If
    '*****************************
    rCell.Value = arr(iPos - 2)
    End Sub


    Now, both code works identically.
    Attaching modCustomSpinButton.xlsm file with both functioning!
    Attached Files Attached Files
    PreetiVerma@xlfox

Similar Threads

  1. Replies: 14
    Last Post: 01-26-2013, 04:58 AM
  2. Replies: 1
    Last Post: 12-04-2012, 08:56 AM
  3. counting consecutive values in an array
    By 5ko in forum Excel Help
    Replies: 3
    Last Post: 12-04-2012, 03:49 AM
  4. Formula to Display Month and Dates Using Spin Button
    By ayazgreat in forum Excel Help
    Replies: 6
    Last Post: 11-21-2012, 10:19 PM
  5. Subtraction Of Series Of Cells' / Array Values
    By PcMax in forum Excel Help
    Replies: 6
    Last Post: 10-26-2012, 11:55 PM

Posting Permissions

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