darrenbutt

New Member
Joined
May 31, 2018
Messages
7
I am looking for some assistance with VBA as I am extremely new to this...

I have a drop down menu in cells D8:D28 that have 5 options (Elec, Mech, Op, C/Over and Project). I want to stop people selecting either Elec or Mech unless there is a numeric value in cell N8:N28.

Please if anyone can help I would be greatly appreciative.

Regards,

Darren
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Darren

How did you create the drop down menu?
 
Upvote 0
ONE WAY... Use a Worksheet Change (Event) code such as:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Independently Assign a Range Name to your Input Area D8:D28 before running this Macro
If Application.Intersect(Target, Range("MyInput")) Is Nothing Then Exit Sub
If Target.Value = "Elec" Or Target.Value = "Mech" Then
    If Not IsNumeric(Target.Offset(0, 10)) Then
        MsgBox "You can't enter Either Elec or Mech if Column N is a Non-Numeric."
        Application.Undo
        Target.Value = ""
        Exit Sub
    End If
End If
End Sub
 
Last edited:
Upvote 0
Hi Jim,

I tried the code you supplied but it doesn't work. I may be doing something wrong as I am extremely new to this but I assigned my range D8:D28 a range name of "MyInput" but I can still select Elec or mech without entering a number in cell N8:N28.
 
Upvote 0
I am looking for some assistance with VBA as I am extremely new to this...

I have a drop down menu in cells D8:D28 that have 5 options (Elec, Mech, Op, C/Over and Project). I want to stop people selecting either Elec or Mech unless there is a numeric value in cell N8:N28.

Please if anyone can help I would be greatly appreciative.

Regards,

Darren

Hi,
create the dropdown from a duplicate list linked to the original one and give a condition to it so it can be dynamic as showed below.



Original ListDuplicated ListValues
aa1
bb2
cc3
dd4
ee5
ff6

<tbody>
</tbody>


Formulas:

Original ListDuplicated ListValues
a=IF(F2<>"",C2,"")1
b=IF(F3<>"",C3,"")2
c=IF(F4<>"",C4,"")3
d=IF(F5<>"",C5,"")4
e=IF(F6<>"",C6,"")5
f=IF(F7<>"",C7,"")6

<tbody>
</tbody>
 
Upvote 0
I am looking for some assistance with VBA as I am extremely new to this...

I have a drop down menu in cells D8:D28 that have 5 options (Elec, Mech, Op, C/Over and Project). I want to stop people selecting either Elec or Mech unless there is a numeric value in cell N8:N28.
Leave the Data Validation List exactly as you had it when you first posted this code, then add the following event code...
Code:
[table="width: 500"]
[tr]
	[td]Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Value As Variant
  If Target.Count <> 1 Then Exit Sub
  If Not Intersect(Target, Range("D8:D28")) Is Nothing Then
    Value = Intersect(Target.EntireRow, Columns("N")).Value
    If Value Like "*[!0-9.]*" Or Value Like "*.*.*" Or Len(Value) = 0 Or Value = "." Then
      If Target.Value = "Elec" Or Target.Value = "Mech" Then
        MsgBox "Sorry but you cannot select ""Elec"" or ""Mech"" unless there is a number in cell N" & Target.Row & "."
        Application.EnableEvents = False
        Target.ClearContents
        Application.EnableEvents = True
      End If
    End If
  End If
End Sub[/td]
[/tr]
[/table]

HOW TO INSTALL Event Code
------------------------------------
If you are new to event code procedures, they are easy to install. To install it, right-click the name tab at the bottom of the worksheet that is to have the functionality to be provided by the event code and select "View Code" from the popup menu that appears. This will open up the code window for that worksheet. Copy/Paste the event code into that code window. That's it... the code will now operate automatically when its particular event procedure is raised by an action you take on the worksheet itself. Note... if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Last edited:
Upvote 0
Thank you to everyone who has replied, it is greatly appreciated.

Rick,

I entered the code you supplied and this works a treat. Thanks a bunch.

Regards,

Darren
 
Upvote 0
Hi Rick,

Can this code be expanded - If someone is clever enough you can currently enter a numeric value into N8:N28 to allow you to select Elec or Mech from the drop down but you can then go and delete the numeric value. Can the code stop someone from deleting the numeric value if either Elec or Mech is selected from the drop down menu is cells D8:D28.
 
Upvote 0
Sub LockCells()
Sheet1.Unprotect
Range("N1:N18").Select
Selection.Locked = True
Sheet1.Protect
End Sub


Sub UnlockCells()
Sheet1.Unprotect
Sheet1.Range("N1:N18").Locked = False 'Unlock the range A1 to B6
Sheet1.Protect
End Sub

First macro to lock and second to unlock the cells
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,669
Members
448,977
Latest member
moonlight6

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