hoof_arted
New Member
- Joined
- Jan 31, 2017
- Messages
- 5
I'm well experienced with Excel but I'm fairly new to VBA. I have a userform that will enter values into the next empty row when the "Enter" button is clicked. The issue I'm having is that, after the next empty row is filled, if the user hits the enter button again it fills the next row with the same values. Is there a way to stop this? Maybe by clearing the userform on enter click? My code is a bit cumbersome, but it does what I want except for that one issue. If anyone sees how I could lighten my code a bit, I'm all ears. Code is as follows:
Thanks in advance for any help.
Code:
Private Sub cmdEnter_Click()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim Found As Range, Found2 As Range
Dim Search As String
Dim iRow As Long
Set ws1 = Worksheets("PWCDaily(1st)")
Set ws2 = Worksheets("PWCDaily(2nd)")
iRow = ws1.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
iRow2 = ws1.Cells(Rows.Count, 8).End(xlUp).Offset(1, 0).Row
iRow3 = ws2.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
iRow4 = ws2.Cells(Rows.Count, 8).End(xlUp).Offset(1, 0).Row
Search = Me.MetricsDTPick.Value
Set Found = ws1.Columns(1).Find(Search, LookIn:=xlValues, LookAt:=xlWhole)
Set Found2 = ws2.Columns(1).Find(Search, LookIn:=xlValues, LookAt:=xlWhole)
If Found Is Nothing And _
Me.shiftCombo.Value = "1st" And _
Me.pwcCombo.Value = "601" Then
Do
ws1.Activate
Cells(iRow, 1).Value = Me.MetricsDTPick.Value
Cells(iRow, 2).Value = Me.schedTxt.Value
Cells(iRow, 3).Value = Me.actualTxt.Value
Cells(iRow, 4).Value = Me.compSeriesTxt.Value
Exit Do
Loop While Found Is Nothing
ElseIf Not Found Is Nothing And _
Me.shiftCombo.Value = "1st" And _
Me.pwcCombo.Value = "601" Then
Do
ws1.Activate
Cells(iRow, 2).Value = Me.schedTxt.Value
Cells(iRow, 3).Value = Me.actualTxt.Value
Cells(iRow, 4).Value = Me.compSeriesTxt.Value
Exit Do
Loop While Not Found Is Nothing
ElseIf Found Is Nothing And _
Me.shiftCombo.Value = "1st" And _
Me.pwcCombo.Value = "721" Then
Do
ws1.Activate
Cells(iRow, 1).Value = Me.MetricsDTPick.Value
Cells(iRow2, 8).Value = Me.schedTxt.Value
Cells(iRow2, 9).Value = Me.actualTxt.Value
Cells(iRow2, 10).Value = Me.compSeriesTxt.Value
Exit Do
Loop While Found Is Nothing
ElseIf Not Found Is Nothing And _
Me.shiftCombo.Value = "1st" And _
Me.pwcCombo.Value = "721" Then
Do
ws1.Activate
Cells(iRow2, 8).Value = Me.schedTxt.Value
Cells(iRow2, 9).Value = Me.actualTxt.Value
Cells(iRow2, 10).Value = Me.compSeriesTxt.Value
Exit Do
Loop While Not Found Is Nothing
ElseIf Found2 Is Nothing And _
Me.shiftCombo.Value = "2nd" And _
Me.pwcCombo.Value = "601" Then
Do
ws2.Activate
Cells(iRow3, 1).Value = Me.MetricsDTPick
Cells(iRow3, 2).Value = Me.schedTxt.Value
Cells(iRow3, 3).Value = Me.actualTxt.Value
Cells(iRow3, 4).Value = Me.compSeriesTxt.Value
Exit Do
Loop While Found2 Is Nothing
ElseIf Not Found2 Is Nothing And _
Me.shiftCombo.Value = "2nd" And _
Me.pwcCombo.Value = "601" Then
Do
ws2.Activate
Cells(iRow3, 2).Value = Me.schedTxt.Value
Cells(iRow3, 3).Value = Me.actualTxt.Value
Cells(iRow3, 4).Value = Me.compSeriesTxt.Value
Exit Do
Loop While Not Found2 Is Nothing
ElseIf Found2 Is Nothing And _
Me.shiftCombo.Value = "2nd" And _
Me.pwcCombo.Value = "721" Then
Do
ws2.Activate
Cells(iRow3, 1).Value = Me.MetricsDTPick.Value
Cells(iRow3, 8).Value = Me.schedTxt.Value
Cells(iRow3, 9).Value = Me.actualTxt.Value
Cells(iRow3, 10).Value = Me.compSeriesTxt.Value
Exit Do
Loop While Found2 Is Nothing
ElseIf Not Found2 Is Nothing And _
Me.shiftCombo.Value = "2nd" And _
Me.pwcCombo.Value = "721" Then
Do
ws2.Activate
Cells(iRow4, 8).Value = Me.schedTxt.Value
Cells(iRow4, 9).Value = Me.actualTxt.Value
Cells(iRow4, 10).Value = Me.compSeriesTxt.Value
Exit Do
Loop While Not Found2 Is Nothing
End If
End Sub
Thanks in advance for any help.
