Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding to Validation list (Excel 2000)

    I have a table with validations in. I will be adding data cells to the bottom of the validation list.

    How do you change the range settings inside the validation to change to include 2 more rows. The following code is an example.

    With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=$D$2:$D$4"
    .IgnoreBlank = True
    .InCellDropdown = True
    .ShowInput = True
    .ShowError = True
    End With

    I would like to change "Formula1:="=$D$2:$D$4"" to Formula1:="=$D$2:$D$6"

    Thanks

    Mario

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Adding to Validation list (Excel 2000)

    Mario, when you add a Validation object the Formula1 parameter is stored in the Validation's Formula1 property, so it is just a matter of parsing that property for the row and adding 2:
    <pre>Option Explicit
    Sub ValidationPlus2()
    Dim strAddress As String
    Dim n As Integer
    Dim intRow As Integer
    With Range("B1").Validation
    strAddress = .Formula1
    n = InStrRev(strAddress, "$")
    intRow = Right(strAddress, Len(strAddress) - n)
    strAddress = Left(strAddress, n) & intRow + 2
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
    Operator:=xlBetween, Formula1:=strAddress
    End With
    End Sub</pre>

    BTW, notice that I left out all of the logical properties: they all default to True, just like you want them. HTH --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Cape Town, South Africa, South Africa
    Posts
    399
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding to Validation list (Excel 2000)

    Thanks it works like a charm

Posting Permissions

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