Results 1 to 6 of 6

Validation riddle with VBA

Threaded View

  1. #1
    Registered User
    Join Date
    12-29-2011
    Location
    San Diego, Ca.
    MS-Off Ver
    Excel 2007
    Posts
    65

    Validation riddle with VBA

    The intent here is simple. On sheet1, Column A1-A100, each cell is allowed a certain entry as determined by a list in B1-B6. Very simple.

    Here is the VBA code that works.

    sub test()
    dim rlist as string
    rList = "$B$1:$B$6"
    
    With Range("A1:A100")
        With .Validation
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="=" & rList
        End With
    End With
    End Sub
    If I add the following variable
    secstr = "$B$6" and substitute the following for rlist:

    rlist=Chr(34) & "$B$1:" & secstr & Chr(34), it results in rlist being exactly "$B$1:$B$6" as before, but the procedure fails, the dreaded Run time error 1004 that hangs on the 2 lines starting with .ADD.

    Here is the modified code.

    sub test()
    dim rlist as string
    dim secstr as string
    
    secstr="$B$6"
    rlist=Chr(34) & "$B$1:" & secstr & Chr(34)
    
    With Range("A1:A100")
    With .Validation
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=" & rList
    End With
    End With
    
    End Sub


    Any ideas?
    Last edited by Leith Ross; 02-02-2019 at 05:24 PM. Reason: Fixed Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. riddle in excel
    By angelos1111 in forum Excel General
    Replies: 7
    Last Post: 01-24-2019, 04:11 PM
  2. update data validation sources if validation values change
    By mauler69 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2016, 05:10 PM
  3. Replies: 3
    Last Post: 05-09-2016, 08:27 PM
  4. validation rules not working when someone copy paste data on validation cell
    By jthakrar in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-17-2010, 03:36 AM
  5. Text wrap riddle!
    By nipakr in forum Excel General
    Replies: 2
    Last Post: 04-23-2008, 05:33 AM
  6. Excel formula riddle
    By egeorge4 in forum Excel General
    Replies: 6
    Last Post: 01-09-2006, 09:55 PM
  7. R1C1 riddle
    By Scriptick in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-07-2005, 03:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1