Results 1 to 4 of 4

Auto generate numbers

Threaded View

  1. #1
    Registered User
    Join Date
    07-28-2010
    Location
    Galveston,TX
    MS-Off Ver
    Excel 2003
    Posts
    7

    Auto generate numbers

    hello, I know this has been talked about many of times here but I can't find a solution that fits what I need. I have created this macro for my company and everything works great but the way I have it now each one of my locations enters there our "Collection #" in my macro. That has led to them entering duplicate numbers. I would like to be able to have the macro auto generate a number into this cell 'G2" for them starting at 0001. Then next time they open it it would enter 0002 and so on. I have tried different methods to no avail. below is the code for the macro. Thank you so much for any help.


    Private Sub cmdOK_Click()
    
    Dim ws As Worksheet
    Set ws = Worksheets("Collections")
    
    'check for a date
    If Trim(Me.txtDate.Value) = "" Then
      Me.txtDate.SetFocus
      MsgBox "Please enter Todays Date"
      Exit Sub
    End If
    
    'check for their collection #
    If Trim(Me.txtCollNum.Value) = "01-" Then
      Me.txtCollNum.SetFocus
      MsgBox "Please enter your Collection #"
      Exit Sub
    End If
    
    'check for a collection receipt
    If Trim(Me.txtReceiptA.Value) = "" Then
      Me.txtReceiptA.SetFocus
      MsgBox "Please enter Collection Recipients Name"
      Exit Sub
    End If
    
    'check for item date
    If Trim(Me.txtItem.Value) = "" Then
      Me.txtItem.SetFocus
      MsgBox "Please enter the Items Date"
      Exit Sub
    End If
    
    'check for a payer
    If Trim(Me.txtPayer.Value) = "" Then
      Me.txtPayer.SetFocus
      MsgBox "Please enter a Payer"
      Exit Sub
    End If
    
    'check for description
    If Trim(Me.txtDescription.Value) = "" Then
      Me.txtDescription.SetFocus
      MsgBox "Please enter a Description"
      Exit Sub
    End If
    
    'check for a amount
    If Trim(Me.txtAmount.Value) = "" Then
      Me.txtAmount.SetFocus
      MsgBox "Please enter an Amount"
      Exit Sub
    End If
    
    'check for instructions
    If Trim(Me.txtInstructions.Value) = "" Then
      Me.txtInstructions.SetFocus
      MsgBox "Please enter Payment Instructions"
      Exit Sub
    End If
    
    'copy the data to the form
    ws.Range("A2").Value = Me.txtDate.Value
    ws.Range("E2").Value = Me.txtReceiptA.Value
    ws.Range("E3").Value = Me.txtReceiptB.Value
    ws.Range("E4").Value = Me.txtReceiptC.Value
    ws.Range("G2").Value = Me.txtCollNum.Value
    ws.Range("A7").Value = Me.txtItem.Value
    ws.Range("A8").Value = Me.txtCheck.Value
    ws.Range("B7").Value = Me.txtPayer.Value
    ws.Range("D7").Value = Me.txtDescription.Value
    ws.Range("G7").Value = Me.txtDue.Value
    ws.Range("H7").Value = Me.txtAmount.Value
    ws.Range("B10").Value = Me.txtDestinationA.Value
    ws.Range("B11").Value = Me.txtDestinationB.Value
    ws.Range("B12").Value = Me.txtDestinationC.Value
    ws.Range("D11").Value = Me.txtInstructions.Value
    
    'clear the data
    Me.txtDate.Value = ""
    Me.txtReceiptA.Value = ""
    Me.txtReceiptB.Value = ""
    Me.txtReceiptC.Value = ""
    Me.txtCollNum.Value = ""
    Me.txtItem.Value = ""
    Me.txtCheck.Value = ""
    Me.txtPayer.Value = ""
    Me.txtDescription.Value = ""
    Me.txtDue.Value = ""
    Me.txtAmount.Value = ""
    Me.txtDestinationA.Value = ""
    Me.txtDestinationB.Value = ""
    Me.txtDestinationC.Value = ""
    Me.txtInstructions.Value = ""
    Me.txtDate.SetFocus
    
     Unload Me
    
    End Sub
    Last edited by MNB123; 07-30-2010 at 10:42 AM.

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