PDA

View Full Version : VBA to Force the User to Enter Data into a Cell before moving to next cell



Sammi8796
04-11-2017, 10:26 AM
I want to force the user to choosesomething from a drop down based on the data that they've entered into anothercell. I was hoping someone could help me with some VBA code. I really don'thave much experience with it but I know I can get the sheet to do what I wantby using VBA. I just don't have enough knowledge to get it done. I’ve searchedthese forums & the web for anything similar to what I’m trying to do and haven’t reallycome up with anything close. I've tried to use data validation and it works,but there's a way they can also just ignore that or they have to choose the reason before entering the number so I would like an alternatemethod.

I have cells in column D where usersenter production numbers each hour. If the numbers are below a certain level(2300), then I want them to choose a reason from the drop down on the same rowin column F. Currently, I have the cell turningred in column F when they fail to reach their production number, but they areignoring it. I want to make it that once they enter a number which falls belowthe target entered in column D, they have no choice but to choose somethingfrom the drop down in column F before they can enter anything else. Therefore theywill have to complete the drop down before changing the next cell in column D.Column D ranges are D5 : 12 and must be entered hourly in order. Also, within the sheet there areother ranges of columns that need to do the same thing, so I will need to repeatthis with other ranges. Any help would be appreciated.

offthelip
04-14-2017, 04:29 PM
this should do it for you:
it forces the selected cell back to column F of the row where the value is less than 2300 until they enter something in column F


Public statusflag
Public selectedrow


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 4 Then
If Target.Value < 2300 Then
statusflag = True
selectedrow = Target.Row

Else
statusflag = False
End If
Else
If Target.Column = 6 Then
statusflag = False
End If
End If
End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If statusflag Then
Cells(selectedrow, 6).Select
End If


End Sub