VBA UserFrom - IF/THEN Function

BradleyLawrence

New Member
Joined
Jan 26, 2017
Messages
2
Hello,

I am new to the forum but i'm pulling my hair on not being able to solve this one!

I have database which is filled in via a user form.
This user form returns the values to four different pages.

I can get the user form to work if i just populate the "Receiver" tab. (The first one)
It fills my data in correctly and returns the values in the correct rows!

If i choose to just enter the "Display" tab then the values are just returning to the top line and not to the correct "next row" command.

The key to my user form is i want to be able to be able to either fill the whole user form in and it returns the values to the correct row OR just fill one section and it populates that one work sheet.

Currently it works if the whole user form is filled in.
It also works for just the receiver tab.
It doesn't work for my "Display" "MyJD" and "ATU" tab.

PLEASE HELP!!!



Private Sub CommandButton1_Click()


Dim lrRE As Long, lrDIS As Long, lrMJD As Long, lrATU As Long


If ComboBoxReceiver <> "" Or TBSerial <> "" Or ComboBoxAccuracy <> "" Or TBActivation <> "" Then
lrRE = Sheets("Receiver").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Receiver").Cells(lrRE + 1, "A").Value = TBCustomer.Text
Sheets("Receiver").Cells(lrRE + 1, "B").Value = TBAccount.Text
Sheets("Receiver").Cells(lrRE + 1, "C").Value = TBNumber.Text
Sheets("Receiver").Cells(lrRE + 1, "D").Value = TBEmail.Text
Sheets("Receiver").Cells(lrRE + 1, "E").Value = ComboBoxReceiver.Text
Sheets("Receiver").Cells(lrRE + 1, "F").Value = TBSerial.Text
Sheets("Receiver").Cells(lrRE + 1, "G").Value = ComboBoxAccuracy.Text
Sheets("Receiver").Cells(lrRE + 1, "H").Value = TBActivation.Text
End If


If ComboBoxDisplay <> "" Then
lrDIS = Sheets("Display").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Display").Cells(lrRE + 1, "A").Value = TBCustomer.Text
Sheets("Display").Cells(lrRE + 1, "B").Value = TBAccount.Text
Sheets("Display").Cells(lrRE + 1, "C").Value = TBNumber.Text
Sheets("Display").Cells(lrRE + 1, "D").Value = TBEmail.Text
Sheets("Display").Cells(lrRE + 1, "E").Value = ComboBoxDisplay.Text
Sheets("Display").Cells(lrRE + 1, "F").Value = TBSerialD.Text
Sheets("Display").Cells(lrRE + 1, "G").Value = TBDActivation
End If


If TBUser <> "" Then
lrMJD = Sheets("MyJD").Range("A" & Rows.Count).End(xlUp).Row
Sheets("MyJD").Cells(lrRE + 1, "A").Value = TBCustomer.Text
Sheets("MyJD").Cells(lrRE + 1, "B").Value = TBAccount.Text
Sheets("MyJD").Cells(lrRE + 1, "C").Value = TBNumber.Text
Sheets("MyJD").Cells(lrRE + 1, "D").Value = TBEmail.Text
Sheets("MyJD").Cells(lrRE + 1, "E").Value = TBUser.Text
Sheets("MyJD").Cells(lrRE + 1, "F").Value = TBPassword.Text
Sheets("MyJD").Cells(lrRE + 1, "G").Value = TBmtg.Text
End If


If TBSerialA <> "" Then
lrATU = Sheets("ATU").Range("A" & Rows.Count).End(xlUp).Row
Sheets("ATU").Cells(lrRE + 1, "A").Value = TBCustomer.Text
Sheets("ATU").Cells(lrRE + 1, "B").Value = TBAccount.Text
Sheets("ATU").Cells(lrRE + 1, "C").Value = TBNumber.Text
Sheets("ATU").Cells(lrRE + 1, "D").Value = TBEmail.Text
Sheets("ATU").Cells(lrRE + 1, "E").Value = TBSerialA.Text
Sheets("ATU").Cells(lrRE + 1, "F").Value = TBTractor.Text
End If






Unload Me


End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Your entire code uses lrRE as the row reference but this is given a value (other than the default) 0 only in the first segment. You need to change all row references to the relevant values

ie IrDIS for display etc.
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

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