vba data validation with if statement

Status
Not open for further replies.

yichuansancun

Board Regular
Joined
Feb 7, 2011
Messages
123
i have the following codes:

Sub GSDDropDown()
If Range("AssignmentType").Value = Range("A1") Then
Range("EntrySub").Validation.Add Type:=xlValidateList, Formula1:="=GSD_Sub_DropDown"
Else
Range("EntrySub").Value = "N/A"
End If
End Sub


it is giving me Run-time Error 13 - Type mismatch. what did i do wrong? :confused:

P
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I can't tell from your code why you are getting a Run-time Error 13.
You should add a .Delete statement otherwise you will get an Error 1004 if you try to run the code when the cell already has Data Validation.

Code:
Sub GSDDropDown()
 If Range("AssignmentType").Value = Range("A1") Then
    With Range("EntrySub").Validation
[COLOR="#0000CD"][B]        .Delete[/B][/COLOR]
        .Add Type:=xlValidateList, Formula1:="=GSD_Sub_DropDown"
    End With
 Else
    Range("EntrySub").Value = "N/A"
 End If
End Sub

When I mock up an example, this works fine.

Assuming that GSD_Sub_DropDown is a Name, what is listed in the Refers to: field for this Name in the Name Manager?

What line of code is the debugger highlighting when the error occurs?
 
Upvote 0
One other possibility...

You'll get a Run-time Error 13 - Type mismatch if either
Range("AssignmentType") or Range("A1") evaluate to errors.

Try this instead to handle that scenario:
Code:
Range("AssignmentType").Text= Range("A1").Text
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,598
Messages
6,120,441
Members
448,966
Latest member
DannyC96

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