Userform Activation - Only once within cell upon Enter key (VBA)

elitef

Board Regular
Joined
Feb 3, 2016
Messages
58
Hello everyone

Really hoping someone can help me as I have been stuck all day trying to figure this out...
I have a spreadsheet which I am working on. I have VBA code which enables a userform depending on the value of a cell

VBA Code:
Private Sub Worksheet_Change(byVal Target As Range)
If [A1].Value = "OTHER" Then
UserFormBox.Show
End If
End Sub

A1 is a drop down via Data Validation with 1,2,3,OTHER
As soon as Other is selected the userform box opens.

The userform that opens is a box with a single text field in it and an OK button. Upon clicking the OK button, it puts the value of the text field in B1

THE ISSUE THAT I AM HAVING IS:

Every time i go into any other cell and press enter in it, it displays the userform box again and again
I need the box to only be displayed when "OTHER" is selected in A1, but nowhere else.

I really hope someone can help me because I am totally clueless at this point...
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  5/13/2021  6:57:18 PM  EDT
If Target.Address = Range("A1").Address And Target.Value = "OTHER" Then UserFormBox.Show
End Sub
 
Upvote 0
According to Logic :​
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then If Target.Text = "OTHER" Then UserFormBox.Show
End Sub
 
Upvote 0
Forgot to mentioned, because I forgot myself really since the behavior is the same, but at A1 I have a combobox (ComboBoxList) which uses the same range as the data validation.
So the above works, BUT when entering Other in the combobox and pressing Enter, it does not pop up the Userform box, instead, I have to go back to the A1 cell after for the box to populate

Any ideas?
 
Upvote 0
Show us the code you have in the Combobox.
If your using a combobox you do not need the the combobox to enter a value in Range("A1")

The script would be sort of like if combox1.value= Userform1 then UserForm1.show
 
Upvote 0
Show us the code you have in the Combobox.
If your using a combobox you do not need the the combobox to enter a value in Range("A1")

The script would be sort of like if combox1.value= Userform1 then UserForm1.show
I've already tried
If ComboBoxList.Value = "Other" Than UserFormBox.show

But, the problem with that is that since "Other" remains in A1, any other cell that I go to and type something in and then press Enter or any other way of getting out of focus of said cell, the UserFormBox shows up again because technically Other is still listed in A1....

Thats the dilemma that I have been having.
 
Upvote 0
I've already tried
If ComboBoxList.Value = "Other" Than UserFormBox.show

But, the problem with that is that since "Other" remains in A1, any other cell that I go to and type something in and then press Enter or any other way of getting out of focus of said cell, the UserFormBox shows up again because technically Other is still listed in A1....

Thats the dilemma that I have been having.
That is because your original code you showed was not written correctly.
Two of us provided code that would work. Did you try the code I provided?
 
Upvote 0
That is because your original code you showed was not written correctly.
Two of us provided code that would work. Did you try the code I provided?
So what you provided worked, but ONLY if "OTHER" is being typed in A1 directly, instead of in the ComboBoxList combobox
When I change the If statement to reflect
If ComboBoxList.Value = "OTHER" Then UserFormBox.Show
The box opens, but upon pressing Enter, I get a runtime error : Run-Time Error 400 Form already displayed; can't show modally
 
Upvote 0
I'm not sure what your wanting to do.
First I thought you wanted to enter "OTHER" In range("A1") to have the Userform open.
But then you started talking about choosing a value in a combobox.
So I'm confused about what your wanting.
 
Upvote 0
I'm not sure what your wanting to do.
First I thought you wanted to enter "OTHER" In range("A1") to have the Userform open.
But then you started talking about choosing a value in a combobox.
So I'm confused about what your wanting.
Apologies
I need for the userform box to appear when Other is entered in a combobox. That combobox is kind of hidden since i made it blend with the cell so forgot it was a combo box as opposed to just a cell, so that was my bad.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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