I'm using a UserForm to enter data in each row starting with B5 to P5 and working its way to row 376.
UserForm coding
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Thermals")
'find first empty row in database
iRow = Worksheets("Thermals").Range("P376").End(xlUp).Row + 1
'check for a date
If Trim(Me.cboDate.Value) = "" Then
Me.cboDate.SetFocus
MsgBox "Please enter the Date and Time then the Temperatures"
Exit Sub
End If
'copy the data to the database
With ws
.Cells(iRow, 2).Value = Me.cboDate.Value
.Cells(iRow, 3).Value = Me.cboTime.Value
.Cells(iRow, 4).Value = Me.txtChWtrSup.Value
.Cells(iRow, 5).Value = Me.txtChWtrRet.Value
.Cells(iRow, 6).Value = Me.txtConWtrRet.Value
.Cells(iRow, 7).Value = Me.txtConWtrSup.Value
.Cells(iRow, 8).Value = Me.txtHeatWtrSup.Value
.Cells(iRow, 9).Value = Me.txtHeatWtrRet.Value
.Cells(iRow, 10).Value = Me.txtSluHeatSup.Value
.Cells(iRow, 11).Value = Me.txtSluHeatRet.Value
.Cells(iRow, 12).Value = Me.txtWstHeatSup.Value
.Cells(iRow, 13).Value = Me.txtWstHeatRet.Value
.Cells(iRow, 14).Value = Me.txtDomHWtrRet.Value
.Cells(iRow, 15).Value = Me.txtDomColdWtr.Value
.Cells(iRow, 16).Value = Me.txtDomHWtrSup.Value
End With
'clear the data
Me.cboDate.Value = ""
Me.cboTime.Value = ""
Me.txtChWtrSup.Value = ""
Me.txtChWtrRet.Value = ""
Me.txtConWtrRet.Value = ""
Me.txtConWtrSup.Value = ""
Me.txtHeatWtrSup.Value = ""
Me.txtHeatWtrRet.Value = ""
Me.txtSluHeatSup.Value = ""
Me.txtSluHeatRet.Value = ""
Me.txtWstHeatSup.Value = ""
Me.txtWstHeatRet.Value = ""
Me.txtDomHWtrRet.Value = ""
Me.txtDomColdWtr.Value = ""
Me.txtDomHWtrSup.Value = ""
Me.cboDate.SetFocus
End Sub
Private Sub UserForm_Initialize()
'Populates the Date & Time Comboboxes
Dim rngDate As Range
Dim rngTime As Range
Dim ws As Worksheet
Set ws = Worksheets("DateTime")
For Each rngDate In ws.Range("DateList")
Me.cboDate.AddItem rngDate.Text
Next rngDate
Set ws = Worksheets("DateTime")
For Each rngTime In ws.Range("TimeList")
Me.cboTime.AddItem rngTime.Text
Next rngTime
End Sub
Private Sub cmdClose_Click()
Sheets("Thermals").Select
ActiveSheet.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Main").Select
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the 'Close' button!"
End If
End Sub
How would I alter this to automatically enter the static UserName then?
Bookmarks