0

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?

1 Answer 1

1

IsEmpty is used for arrays. use the below:

With ws3
     If Not Me.SecondCompetitor.Value = "" Then 'This line could also be Me.SecondCompetitor.Value = vbNullString
        .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 
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, I understand! Thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.