VBA to check if an Userform Textbox is empty and paste a formula in a cell

Hmerman

Board Regular
Joined
Oct 2, 2016
Messages
102
Hello all,
I have created an Userform with two combo boxes and two textboxes to capture information such as names and farms from a list with the combo boxes and dates and emails with the textboxes in different cells on the same sheet called "Aanbevelingsblad".

What I have tried is to write a code that checks If the textbox for the emails are empty Then pastes a formula that matches the name and farm with the email in a list on another sheet named "Adresse!"; Else it places the email that was entered in the designated cell B8.

When I click the submit button the code does not place the Formula in cell B8 If empty, instead it says False when the textbox is empty. The Else part works well.
<code>

Dim nmRg As Range
Dim plRang As Range
Dim eposRgn As Range

Set dtRng = Sheets("Aanbevelingsblad").Range("H6")
Set nmRg = Sheets("Aanbevelingsblad").Range("B6")
Set plRang = Sheets("Aanbevelingsblad").Range("B7")
Set eposRgn = Sheets("Aanbevelingsblad").Range("B8")

dtRng = Me.txbDatum
nmRg = Me.cmbNm
plRang = Me.cmbPs

'This is the part that does not place the formula in cell B8 when I click submit
If Trim(txbEpos.Value & vbNullString) = vbNullString Then
eposRgn = Me.txbEpos.Text = "=INDEX(Adresse!$C$2:$C$500,MATCH($B6&$B7,INDEX(Adresse!$A$2:$A$500&Adresse!$B$2:$B$500,),0))"

Else
eposRgn = Me.txbEpos

End If

</code>

Can someone please assist me to make the code in red functional?

Regards
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hello again,
I solved it!:)

<code>
'Just had to remove the Me. form from the line, since it did not need to fill cell B8 from the textbox on the userform
If Trim(txbEpos.Value & vbNullString) = vbNullString Then
eposRgn.Formula = "=INDEX(Adresse!$C$2:$C$500,MATCH($B$6&$B$7,INDEX(Adresse!$A$2:$A$500&Adresse!$B$2:$B$500,),0))"

Else
eposRgn = Me.txbEpos
</code>

Regards
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top