Hey All!
So I've just started working with Userforms, and I'm trying to build a form to enter information that I have to enter into my workbook daily for my business. The data is sales data and a simple form to enter the data in daily would be incredible.
So here is what I've got... sorry about all the comments, but as I learn, I like to note what I did.
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("2014")
'find first empty row in database
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim currentRowValue As String
sourceCol = 3 'column F has a value of 6
rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
'for every row, find the first blank cell and select it
For currentRow = 1 To rowCount
currentRowValue = Cells(currentRow, sourceCol).Value
If IsEmpty(currentRowValue) Or currentRowValue = "" Then
Cells(currentRow, sourceCol).Select
Exit For 'This is missing...
End If
Next
End Sub
'check for Net Sales Entry
If Trim(Me.tbNetSales.Value) = "" Then
Me.txtPart.SetFocus
MsgBox "You forgot to enter today's Net Sales..."
Exit Sub
End If
'copy the data to the database
'use protect and unprotect lines,
' with your password
' if worksheet is protected
' Row C is equal to 3
With ws.Cells(iRow, 3).Value = Me.tbNetSales.Value
' .Unprotect Password:="password"
' .Protect Password:="password"
End With
'clear the data
Me.tbNetSales.Value = ""
Me.tbNetSales.SetFocus
End Sub
Now, the form loads fine, but when I enter the data for the days net sales, nothing happens... not even an error. What did I do wrong here?
Bookmarks