Results 1 to 4 of 4

Referncing data in column A to determine Row for data entry

Threaded View

  1. #1
    Registered User
    Join Date
    04-13-2010
    Location
    Ames, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    1

    Referncing data in column A to determine Row for data entry

    I am trying to create a User Form that will enter data into a spreadsheet. I want the user of the form to be able to enter a date as the first piece of information in the User Form, this date will then correspond with the row in which the remaining data is entered (note all relevant dates are already in the spreadsheet so I am just doing a find function to locate the date in the row corresponding to where I want the data to go)

    I am very new to VBA so I am not sure that I am even approaching this the right way but here is what I have so far:

    Private Sub cmdAdd_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Sales")
    
    'find matching data row in database
    iRow = Cells.Find(What:=Me.txtDate.Value, After:=ws.Cells(1, 1), LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
        
    'check for a date
    If Trim(Me.txtDate.Value) = "" Then
      Me.txtDate.SetFocus
      MsgBox "Please enter a date"
      Exit Sub
    End If
    
    'copy the data to the database
    ws.Cells(iRow, 5).Value = Me.txtSmall.Value
    ws.Cells(iRow, 6).Value = Me.txtMedium.Value
    ws.Cells(iRow, 7).Value = Me.txtLarge.Value
    ws.Cells(iRow, 8).Value = Me.txtXL.Value
    
    'clear the data
    Me.txtSmall.Value = ""
    Me.txtMedium.Value = ""
    Me.txtLarge.Value = ""
    Me.txtXL.Value = ""
    Me.txtDate.SetFocus
    
    End Sub

    I'm not sure why this isn't working, I am getting an error message:

    Run-time error '1004':
    Application-defined or object-defined error

    Not sure what it means but I did notice when I run the cursor over iRow in the ws.cells(iRow, 5) it is displaying a value of -1 which seems wrong to me.

    Any help would be greatly appreciated, thanks!
    Last edited by dtt084; 04-13-2010 at 02:13 PM.

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