+ Reply to Thread
Results 1 to 2 of 2

Modifying a Input Box and Its Actions

Hybrid View

  1. #1
    Registered User
    Join Date
    10-06-2006
    Posts
    15

    Modifying a Input Box and Its Actions

    OK, I have some code for an input box seen here:

    Sub AddUnits()
    On Error GoTo HandleError
    Dim units
    Dim newBox
    newBox = InputBox("Please enter units", "Units")
    HandleError:
    End Sub

    There are several things I want to do to it but am not quite sure how to achieve them. I have listed them below...

    1. I want it so that when the Macro is activated the input starts at Cell 1 in Column C and descends down the column as data is enter. (Example: from Cell 1 to 2 to 3 to 4 and so on as data is entered.)

    2. I want it so that when a number of units is entered in the message box for a cell the data in that cell is automatically added to the number entered in the input box. (Example: 25 is in Cell C5 and 10 is entered in the input box, then 35 would show up in Cell C5 and the input box would move to cell C6)

    3. I want it so that when a letter is entered in the input box the input box will move to a different column and start at the first cell in that column and do the same thing as the others. (Example: The input box is in Cell C20 and A is entered, the input box would then shift to cell J1 and data entry would begin there.

    4. I also have some code that will close the program and save, is there anyway to make code to put a button on the input box for that?

    If you even know part of this that would greatly help. Any suggestions or assistance is greatly appreciated.

  2. #2
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Sub macroForEddie()
    Dim myCell As Range
    Dim myString As String
    Dim myValue As Single
        
        
        Set myCell = Range("C1")
        
        Do
            myString = InputBox("", "enter something for cell " & myCell.Address(False, False))
            If IsNumeric(myString) Then
                'user entered a number
                myValue = Val(myString)
                myCell = myCell + myValue
                myRow = myCell.Row
                'if we are out of rows, move to the next column
                If myRow > 2 ^ 16 - 1 Then
                    Set myCell = Cells(1, myCell.Column + 1)
                Else
                    Set myCell = myCell.Offset(1, 0)
                End If
            Else
                'user entered a letter
                Set myCell = Nothing
                'is this a valid column address?
                On Error Resume Next
                Set myCell = Range(myString & 1)
                If Err Or myCell Is Nothing Then
                    Err.Clear
                    GoTo leave
                End If
            End If
            
        Loop While myString <> ""
    
    leave:
        myChoice = MsgBox("Do you want to save?", vbYesNo, "Exiting Eddie's Program")
        If myChoice = vbYes Then
            ThisWorkbook.Save
        End If
        ThisWorkbook.Close
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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