MS Excel VBA Code - Data Validation List Error

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
439
Office Version
  1. 2019
Platform
  1. Windows
Thanks in advance for your assistance. Why do I get the following error and how do I fix it:

Error: "Run-tim error '438: Object doesn't support this propert of method"

Code that gives error:
Rich (BB code):
Cells(7, 3).Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:=DataValList

I did previously do something similar when it was read from a spreadsheet: VBA Code to Extract Data from a List and Making a Validation , but in this case, I am not reading the values in.

Rich (BB code):
Option Explicit

Sub DataValListError()

 Application.ScreenUpdating = False

  '_______________________________________________________________________________________________________
  'Dim
    
     Dim i As Long, j As Long
     
     Dim StringList() As String, Size As Long
     
     Dim DataValList As Variant
    
    

  '_______________________________________________________________________________________________________
  'Code -
    
    'Set up the array
        'Set the size of the array
         Size = 5
            
        'Redim the size of the array
         ReDim StringList(Size)
        
        'Initialize each element of the array
         StringList(1) = "$APPLES"
         StringList(2) = "$ORANGES"
         StringList(3) = "$PEARS"
         StringList(4) = "$TANGERINES"
         StringList(5) = "$BANANAS"
        
        
        'DataValList
         For i = 1 To Size
            DataValList = DataValList & StringList(i) & ", "
         Next i
        
        'Remove the extra comma and space
         DataValList = Left(DataValList, Len(DataValList) - 2)
        
        'Delete old validation list and insert new one
         Cells(7, 3).Validation.Delete
         Cells(7, 3).Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:=DataValList
        
 

  '_______________________________________________________________________________________________________

   Application.ScreenUpdating = True


End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Needs to be

Rich (BB code):
Cells(7, 3).Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:=DataValList
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

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