VBA Code to Calculate Formula in Cells

Helen87

New Member
Joined
Sep 20, 2017
Messages
1
So, I'm a complete novice at this VBA but have managed to create a code which works. However, I want to add another level to it.Basically, I've got a sheet with a form combo box (named in the VBA code as ComboBox) on, which when the selection changes, prompts for a password to be entered. It gives two chance for the password to be entered, then asks the user to try again. When the drop down changes, there's a Vlookup formula in cells F7:F9, which looks up the value in cell E1 (the reference cell for the combo box), in the array on Sheet 2, A2:D7. What I really want is for this Vlookup formula only to be calculated if the password has been entered correctly, otherwise I want them to be blank.The code I have at the moment is:Sub ComboBox_Change() With ThisWorkbook.Sheets("Sheet1").Shapes("ComboBox").ControlFormat Select Case .List(.Value) Case "J Smith": Password1 Case "K Elliot": Password2 Case "T Harrison": Password3 Case "S Jones": Password4 Case "M Barker": Password5 End Select End WithEnd SubSub Password1()pword = Application.InputBox("Please enter your password", "Password Required")If pword = "Test1" Then Worksheets("Sheet1").Visible = TrueElsepword = Application.InputBox("Please enter your password", "Password Required")If pword = "Test1" Then Worksheets("Sheet1").Visible = TrueElse MsgBox "You have entered your password incorrectly twice. Please re-select your name and try again"End IfEnd IfEnd SubSub Password2()pword = Application.InputBox("Please enter your password", "Password Required")If pword = "Test2" Then Worksheets("Sheet1").Visible = TrueElsepword = Application.InputBox("Please enter your password", "Password Required")If pword = "Test2" Then Worksheets("Sheet1").Visible = TrueElse MsgBox "You have entered your password incorrectly twice. Please re-select your name and try again"End IfEnd IfEnd SubSub Password3()pword = Application.InputBox("Please enter your password", "Password Required")If pword = "Test3" Then Worksheets("Sheet1").Visible = TrueElsepword = Application.InputBox("Please enter your password", "Password Required")If pword = "Test3" Then Worksheets("Sheet1").Visible = TrueElse MsgBox "You have entered your password incorrectly twice. Please re-select your name and try again"End IfEnd IfEnd SubSub Password4()pword = Application.InputBox("Please enter your password", "Password Required")If pword = "Test4" Then Worksheets("Sheet1").Visible = TrueElsepword = Application.InputBox("Please enter your password", "Password Required")If pword = "Test4" Then Worksheets("Sheet1").Visible = TrueElse MsgBox "You have entered your password incorrectly twice. Please re-select your name and try again"End IfEnd IfEnd SubSub Password5()pword = Application.InputBox("Please enter your password", "Password Required")If pword = "Test5" Then Worksheets("Sheet1").Visible = TrueElsepword = Application.InputBox("Please enter your password", "Password Required")If pword = "Test5" Then Worksheets("Sheet1").Visible = TrueElse MsgBox "You have entered your password incorrectly twice. Please re-select your name and try again"End IfEnd IfEnd SubAnyone have any ideas? Is it even possible?? Am I making sence??!Thanks in advance!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,215,514
Messages
6,125,269
Members
449,219
Latest member
daynle

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