Hi,
this might be a simple thing or I have missed something completely
This is the current code for a userform to add data, however I want the form to add data to a sheet dependant on the name, which is in a cell, or whether I should add the name to userform and whether it would add the data to appropriate named sheet.
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("John") - this would be either from the userform or a reference to a cell on a sheet
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
If Trim(Me.txtDate.Value) = "" Then
Me.txtDate.SetFocus
MsgBox "Please enter the date"
Exit Sub
End If
With ws
.Unprotect Password:=""
.Cells(iRow, 1).Value = Me.txtDate.Value
.Cells(iRow, 2).Value = Me.txtTime.Value
.Cells(iRow, 3).Value = Me.txtReason.Value
.Protect Password:=""
End With
Me.txtDate.Value = ""
Me.txtTime.Value = ""
Me.txtReason.Value = ""
Me.txtDate.SetFocus
End Sub
I have attached a sample to see if it helps make it clearer as to what I am trying to explain.
Thanks in advance
Bookmarks