Results 1 to 4 of 4

Combobox Selection To Insert Data

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-26-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    182

    Exclamation Combobox Selection To Insert Data

    Hi

    I am having a mental blank I can't remember the code to do the following

    I want to be able to add items to worksheets based on the worksheet selection in a Combobox

    I dont want the Category name selected in the Combobox to be saved to the worksheet it is only used to select which worksheet the other data is to be saved to.

    Any help would be appreciated

    Private Sub cmdAdd_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets(",")
    
    'find first empty row in database
    iRow = ws.Cells(Rows.Count, 1) _
      .End(xlUp).Offset(1, 0).Row
      
    'check for a Category
    If Trim(Me.cboCategory.Value) = "" Then
      Me.cboCategory.SetFocus
      MsgBox "Please Select a Category"
      Exit Sub
    End If
    
    'check for a Product
    If Trim(Me.txtProduct.Value) = "" Then
      Me.cboCategory.SetFocus
      MsgBox "Please Enter a Product Description"
      Exit Sub
    End If
    
    'copy the data to the database
    ws.Cells(iRow, 1).Value = Me.txtProduct.Value
    ws.Cells(iRow, 2).Value = Me.cboUnit.Value
    ws.Cells(iRow, 3).Value = Me.txtPrice.Value
    ws.Cells(iRow, 4).Value = Me.txtLabour.Value
    
    
    
    'clear the data
    Me.cboCategory.Value = ""
    Me.txtProduct.Value = ""
    Me.cboUnit.Value = ""
    Me.txtPrice.Value = ""
    Me.txtLabour.Value = ""
    
    Me.cboCategory.SetFocus
    
    End Sub
    Last edited by Mooseman60; 12-05-2010 at 09:11 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