mercredi 13 juillet 2016

Excel VBA UserForm- If Not IsEmpty Then

I am making a userform that asks for input from the user.

There are lots of inputs, but I am having problems with one section in particular. If a user enters ANYTHING into the textbox (named SecondCompetitor), I want the function to place some values into one of my excel worksheets (named ws4).

Here is the code I have written:

With ws3
     If Not IsEmpty(Me.SecondCompetitor.Value) Then
        .Cells(iRow3, 14).Value = Me.Ticker.Value
        .Cells(iRow3, 2).Value = Me.Rec1.Value
        .Cells(iRow3, 3).Value = Me.Rec2.Value
        .Cells(iRow3, 4).Value = Me.Rec3.Value
        .Cells(iRow3, 5).Value = Me.Rec4.Value
        .Cells(iRow3, 6).Value = Me.Rec5.Value
        .Cells(iRow3, 7).Value = Me.Rec6.Value
        .Cells(iRow3, 8).Value = Me.Rec7.Value
        .Cells(iRow3, 9).Value = Me.Rec8.Value
        .Cells(iRow3, 10).Value = Me.Rec9.Value
        .Cells(iRow3, 15).Value = Me.FirstCompetitor.Value
        .Cells(iRow3, 17).Value = Me.SecondCompetitor.Value
        .Cells(iRow3, 19).Value = Me.Winner.Value
        .Cells(iRow3, 20).Value = Me.Exploration.Value
        .Cells(iRow3, 21).Value = Me.DateAdded.Value
    End If
End With 

When I actually execute the code, the values are placed in the rows REGARDLESS of whether or not a user has actually inputted anything into the SecondCompetitor textbox.

Any suggestions on what the problem may be?

Aucun commentaire:

Enregistrer un commentaire