Data validation with VBA error

Mr2017

Well-known Member
Joined
Nov 28, 2016
Messages
644
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

I've written a macro which copies data from one sheet to another, then adds data validation in the last column.

However, I keep on getting a debug error when the code gets to the data validation part of the macro.

It says "Application-defined or object-defined error." It comes up after the ".delete" line in the code below.

Does anyone know why this may be? The data validation list is in cells B6 to B8 of Sheet 15 and should apply to cells S4:S100 in Sheet 4. I originally recorded the data validation steps to get the list of actions (please see below).

Thanks in advance.

Code:
Sub Columns()


Sheet15.Activate
Range("A1:R2").Copy
Sheet4.Activate
Range("B2").PasteSpecial (xlPasteAll)
Range("B2").End(xlToRight).Offset(1, 0).Select
    Range("S4:S100").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=Sheet15!$b$6:$b$8"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With


Columns("S:S").AutoFit


End Sub
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
What is the actual name (on the sheet tab) of the worksheet with the list?
It looks as though you are trying to use the sheet codename.
 
Upvote 0
Hi Fluff

The name of the tab of the worksheet with the list is "Column Titles"

But, yes, I'd prefer to use the Sheet codename / "back of the house" instead of "front of the house" name, in case someone changes the "front of the house" name.
 
Upvote 0
In that case you will need to change the Sheet15 in the formula to Column Titles
Excel cannot see sheet code names.
 
Upvote 0
Another options is
Code:
Formula1:="='" & Sheet15.Name & "'!$b$6:$b$8"
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,217,349
Messages
6,136,051
Members
449,985
Latest member
rittersportyummy

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