Frage

I have created this investor mail list for work purpose, and need to add some more functions:

I need to "lock" the inputbox, meaning that you have to fill out all the options otherwise an msgbox will occur "Please fill in all the options".

I also need to lock the entire spreadsheet - so it's only possible to add an investor to the mail list through the inputbox. It should only be possible to add an investor without the inputbox through the administrator

I have search all over the internet, and cannot find such functions

Help is much appreciated!

Private Sub OKButton_Click()
Dim emptyrow As Long

'Make sheet1 active
Ark1.Activate

'determine emptyrow
emptyrow = WorksheetFunction.CountA(Range("A:A")) + 1

'Transfer information
Cells(emptyrow, 1).Value = Email.Value
Cells(emptyrow, 2).Value = Bank.Value
Cells(emptyrow, 3).Value = FirstName.Value
Cells(emptyrow, 4).Value = Surname.Value
Cells(emptyrow, 5).Value = AddIn.Value
Cells(emptyrow, 6).Value = TypeComboBox.Value



If CheckBox1.Value = True Then Cells(emptyrow, 7).Value = CheckBox1.Caption

If CheckBox2.Value = True Then Cells(emptyrow, 7).Value = Cells(emptyrow, 7).Value & " " & CheckBox2.Caption

If CheckBox3.Value = True Then Cells(emptyrow, 7).Value = Cells(emptyrow, 7).Value & " " & CheckBox3.Caption

If CheckBox4.Value = True Then Cells(emptyrow, 7).Value = Cells(emptyrow, 7).Value & " " & CheckBox4.Caption

If CheckBox5.Value = True Then Cells(emptyrow, 7).Value = Cells(emptyrow, 7).Value & " " & CheckBox5.Caption

Unload Me

MsgBox "Investor successfully added"


End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()

'empty all textboxes

Email.Value = ""
Bank.Value = ""
FirstName.Value = ""
Surname.Value = ""
AddIn.Value = ""

TypeComboBox.Clear

'Fill dinnercombobox
With TypeComboBox
.AddItem "Bank"
.AddItem "Corporate"
.AddItem "DCM"
.AddItem "Fund Manager"
.AddItem "FSA"
.AddItem "Investor"
.AddItem "Insurance"
.AddItem "Magazine"
.AddItem "Other"
.AddItem "Pension Fund"
.AddItem "Rating agency"



End With

'uncheck wishbox
CheckBox1.Value = False
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False

'set focus on email box
Email.SetFocus

End Sub
War es hilfreich?

Lösung

Here's how you'll force to fill in all the fields before they can press the OK button:

Private Sub Email_Change()

If Me.Email.Value <> "" And Me.Bank.Value <> "" And Me.FirstName.Value <> "" And _
    Me.Surname.Value <> "" And Me.AddIn.Value <> "" And Me.TypeComboBox.Value <> "" Then

    Me.OKButton.Enabled = True
    MsgBox "Some Fields are missing!"
Else
    Me.OKButton.Enabled = False
End If

End Sub

You put this code on Email Textbox Change event.
And you will need to put above code in all your Textboxes Change event.
Meaning, everytime Textboxes value changes, it will check if other Texboxes are empty or not.
The test I did is for empty, you can modify it if you have certain conditions that you want to meet.
Hope this gets you started.

Andere Tipps

L42 gave a good answer to the first half of your question, so I won't address that. You can use Excel's Protect Sheet to prevent users from editing cells, but that prevents your VBA code from editing the cells also. You can work around this by having the sheet protected and then using VBA to unprotect it just before making the changes and protecting it again afterward.

Sheet1.Unprotect Password:=yourPassword

'Update the values you want here

Sheet1.Protect Password:=yourPassword

If your users are pretty savvy and you're concerned about them reading your code and finding the password, you can password protect the VBA code. To protect your code, open the Excel Workbook and go to Tools>Macro>Visual Basic Editor (Alt+F11). Now, from within the VBE go to Tools>VBAProject Properties and then click the Protection page tab and then check "Lock project from viewing" and then enter your password and again to confirm it. After doing this you must save, close & reopen the Workbook for the protection to take effect.

Hope this helps!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top