Consulting

Results 1 to 2 of 2

Thread: Data Validation code error

  1. #1
    VBAX Regular
    Joined
    Apr 2010
    Posts
    32
    Location

    Question Data Validation code error

    I'm getting an 'application-defined or object-defined error' error when executing the code below.

    it produces the error on the line in red.

    [VBA] For r = 4 To 5000
    If ActiveSheet.Cells(r, 2).Value = "" Then
    ActiveSheet.Range("B" & r).Select
    With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=buildings"

    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
    End With
    ActiveSheet.Cells(r, 1).Formula = "=IF(B" & r & "<>"""",VLOOKUP(B" & r & ",Buildings!A:B,2,FALSE)"
    Exit For
    End If
    Next r
    [/VBA]

    The sheet is not locked/protected and the exact same code works on another workbook that I've created.

    Can anyone help?

    Thanks.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I the light of your comments, it would probably help to post the workbook.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •