VBA Enter key problem

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
778
Office Version
  1. 2016
Platform
  1. Windows
I have a cell with a validation drop down. I also have the code below that applies formatting to a range depending on the value chosen in the validation cell.

The problem is that validation enters the value. But doesn’t “Press Enter” afterwards. So the vba won’t pick up the value and run.

I’ve tried using a separate combo box, SendKeys ~, SendKeys ENTER etc but still can’t think of a way to do it.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$2" And Target = "Dogs" Then
Range("Row18").Select
Selection.NumberFormat = "0.00%"
End If
If Target.Address = "$B$2" And Target = "Cats" Then
Range("Row18").Select
Selection.NumberFormat = "0"
End If
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Just in case anyone reads this. I have now found out why the code Ruddles supplied would not work. It was due to a function I have in the workbook. The function adds together all the text from a range of cells. I have now stopped using this function and the code is working perfectly.

Function CombineTextRange(myRange As Range)

Dim cell As Range
For Each cell In myRange
If Len(cell) > 0 Then
CombineTextRange = CombineTextRange & cell.Value & " "
End If
Next cell
CombineTextRange = Left(CombineTextRange, Len(CombineTextRange) - 1)

End Function
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

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