Results 1 to 4 of 4

Prompt Box Macro

Threaded View

  1. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Prompt Box Macro

    Hello hassankhan,

    The attached workbook uses a VBA UserForm to validate and input the data into column "A" starting at cell "A2". Here is the UserForm code.

    To run the macro press the keys Ctrl+e
    Dim RepeatCount As Integer
    
    Private Sub CommandButton1_Click()
     'DONE
     
      Dim I As Long
      Dim LastEntry As Range
      Dim Rng As Range
      Dim RngEnd As Range
      
      
        Set Rng = ActiveSheet.Range("A2")
        Set RngEnd = Cells(Rows.Count, Rng.Column).End(xlUp)
        Set LastEntry = IIf(RngEnd.Row <= Rng.Row, Rng, RngEnd.Offset(1, 0))
        
        For I = 1 To RepeatCount
          LastEntry = TextBox1
          Set LastEntry = LastEntry.Offset(1, 0)
        Next I
        
        TextBox1.SelStart = 0
        TextBox1.SelLength = Len(TextBox1)
        TextBox1.SetFocus
        
    End Sub
    
    Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
      
      If TextBox2 = "" Then Exit Sub
      
      On Error Resume Next
        RepeatCount = CInt(TextBox2.Value)
    
      If Err <> 0 Or RepeatCount < 0 Then
        Cancel = True
        MsgBox "You must enter a number greater than zero."
        TextBox2.SelStart = 0
        TextBox2.SelLength = Len(TextBox2)
        TextBox2.SetFocus
      End If
      
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

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