Results 1 to 6 of 6

Trying to add input box to code and use value in a counter

Threaded View

  1. #1
    Registered User
    Join Date
    09-24-2010
    Location
    Illinois, USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Trying to add input box to code and use value in a counter

    The following code in Outside Storage2 works fine:

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        
        Range("C1").Select 'ASN cell
        If Target.Column = 3 And Target.Row = 1 Then
            Target.Offset(5, -2).Activate
        End If
       
            If Target.Column = 1 Then
                Target.Offset(0, 1).Activate
            End If
     
            If Target.Column = 2 Then
                Target.Offset(1, -1).Activate
            End If
        
    End Sub
    I tried to add an input box and use the value entered in a counter, but the code does not work. This is the code in Outside Storage3:

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        
        Dim strUsrIn As Integer  'also tried Dim strUsrln As String
        Dim J As Integer
        Range("E2").Select
        
    'InputBox # 1 - Number of Pallets
         strUsrIn = InputBox("Enter Number of Pallets")
         If IsNull(strUsrIn) Then Exit Sub
         Range("E2").Value = strUsrIn
        
           
        Range("C1").Select 'ASN cell
        If Target.Column = 3 And Target.Row = 1 Then
            Target.Offset(5, -2).Activate
        End If
            
        J = 6
        For J = 6 To strUsrIn + 6
            If Target.Column = 1 Then
                Target.Offset(0, 1).Activate
            End If
     
            If Target.Column = 2 Then
                Target.Offset(1, -1).Activate
            End If
        Next
            
    End Sub
    I want the input box to open upon the opening of the spreadsheet, but it doesn't. If I enter a value in C1, then the input box opens. But then I can't get the input box to close. It results in an endless loop.

    I have attached both spreadsheets. Any help will be greatly appreciated.
    Attached Files Attached Files

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