+ Reply to Thread
Results 1 to 6 of 6

Data validation and empty cells

  1. #1
    Kris
    Guest

    Data validation and empty cells


    range("d1").Validation.add formula1:=
    "=$A$1:$A$7",Type:=xlValidateList,operator:=xlBetween


    How to avoid empty entries in drop down box if some of cell from A1:A7
    are empty?

    Thanks

  2. #2
    Tom Ogilvy
    Guest

    Re: Data validation and empty cells

    create another range where there are no spaces and use that.

    --
    Regards,
    Tom Ogilvy


    "Kris" <[email protected]> wrote in message
    news:[email protected]...
    >
    > range("d1").Validation.add formula1:=
    > "=$A$1:$A$7",Type:=xlValidateList,operator:=xlBetween
    >
    >
    > How to avoid empty entries in drop down box if some of cell from A1:A7
    > are empty?
    >
    > Thanks




  3. #3
    Jim Thomlinson
    Guest

    RE: Data validation and empty cells

    This should be a good start. It returns the address of the non blank cells...

    Private Function NonBlank(ByVal rng As Range) As Range
    Dim rngCurrent As Range
    Dim rngNonBlank As Range

    For Each rngCurrent In rng
    If rngCurrent.Value <> "" Then
    If rngNonBlank Is Nothing Then
    Set rngNonBlank = rngCurrent
    Else
    Set rngNonBlank = Union(rngCurrent, rngNonBlank)
    End If
    End If
    Next rngCurrent
    Set NonBlank = rngNonBlank
    End Function

    Sub test()
    Dim rng As Range

    Set rng = NonBlank(Range("A1:A7"))
    If rng Is Nothing Then
    MsgBox "They are all blank"
    Else
    MsgBox rng.Address
    End If
    End Sub

    --
    HTH...

    Jim Thomlinson


    "Kris" wrote:

    >
    > range("d1").Validation.add formula1:=
    > "=$A$1:$A$7",Type:=xlValidateList,operator:=xlBetween
    >
    >
    > How to avoid empty entries in drop down box if some of cell from A1:A7
    > are empty?
    >
    > Thanks
    >


  4. #4
    Tom Ogilvy
    Guest

    Re: Data validation and empty cells

    I get the message something like:
    "You can not use unions, intersections or array constants for data
    validation criteria"

    or are you suggesting building a comma separated string from the result and
    using a constant argument?

    --
    Regards,
    Tom Ogilvy



    "Jim Thomlinson" <[email protected]> wrote in
    message news:[email protected]...
    > This should be a good start. It returns the address of the non blank

    cells...
    >
    > Private Function NonBlank(ByVal rng As Range) As Range
    > Dim rngCurrent As Range
    > Dim rngNonBlank As Range
    >
    > For Each rngCurrent In rng
    > If rngCurrent.Value <> "" Then
    > If rngNonBlank Is Nothing Then
    > Set rngNonBlank = rngCurrent
    > Else
    > Set rngNonBlank = Union(rngCurrent, rngNonBlank)
    > End If
    > End If
    > Next rngCurrent
    > Set NonBlank = rngNonBlank
    > End Function
    >
    > Sub test()
    > Dim rng As Range
    >
    > Set rng = NonBlank(Range("A1:A7"))
    > If rng Is Nothing Then
    > MsgBox "They are all blank"
    > Else
    > MsgBox rng.Address
    > End If
    > End Sub
    >
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "Kris" wrote:
    >
    > >
    > > range("d1").Validation.add formula1:=
    > > "=$A$1:$A$7",Type:=xlValidateList,operator:=xlBetween
    > >
    > >
    > > How to avoid empty entries in drop down box if some of cell from A1:A7
    > > are empty?
    > >
    > > Thanks
    > >




  5. #5
    Jim Thomlinson
    Guest

    Re: Data validation and empty cells

    Oops... For the life of me I thought you could use non-contiguious ranges in
    validation arguments... Should have tested it all the way. Give this a try...

    Private Function NonBlank(ByVal rng As Range) As String
    Dim rngCurrent As Range
    Dim strNonBlank As String

    For Each rngCurrent In rng
    If rngCurrent.Value <> "" Then
    If Len(strNonBlank) = 0 Then
    strNonBlank = rngCurrent.Value
    Else
    strNonBlank = strNonBlank & ", " & rngCurrent.Value
    End If
    End If
    Next rngCurrent
    NonBlank = strNonBlank
    End Function

    Sub test()
    Dim str As String

    str = NonBlank(Range("A1:A7"))
    If Len(str) = 0 Then
    MsgBox "They are all blank"
    Else
    MsgBox str
    End If
    End Sub
    --
    HTH...

    Jim Thomlinson


    "Tom Ogilvy" wrote:

    > I get the message something like:
    > "You can not use unions, intersections or array constants for data
    > validation criteria"
    >
    > or are you suggesting building a comma separated string from the result and
    > using a constant argument?
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    > "Jim Thomlinson" <[email protected]> wrote in
    > message news:[email protected]...
    > > This should be a good start. It returns the address of the non blank

    > cells...
    > >
    > > Private Function NonBlank(ByVal rng As Range) As Range
    > > Dim rngCurrent As Range
    > > Dim rngNonBlank As Range
    > >
    > > For Each rngCurrent In rng
    > > If rngCurrent.Value <> "" Then
    > > If rngNonBlank Is Nothing Then
    > > Set rngNonBlank = rngCurrent
    > > Else
    > > Set rngNonBlank = Union(rngCurrent, rngNonBlank)
    > > End If
    > > End If
    > > Next rngCurrent
    > > Set NonBlank = rngNonBlank
    > > End Function
    > >
    > > Sub test()
    > > Dim rng As Range
    > >
    > > Set rng = NonBlank(Range("A1:A7"))
    > > If rng Is Nothing Then
    > > MsgBox "They are all blank"
    > > Else
    > > MsgBox rng.Address
    > > End If
    > > End Sub
    > >
    > > --
    > > HTH...
    > >
    > > Jim Thomlinson
    > >
    > >
    > > "Kris" wrote:
    > >
    > > >
    > > > range("d1").Validation.add formula1:=
    > > > "=$A$1:$A$7",Type:=xlValidateList,operator:=xlBetween
    > > >
    > > >
    > > > How to avoid empty entries in drop down box if some of cell from A1:A7
    > > > are empty?
    > > >
    > > > Thanks
    > > >

    >
    >
    >


  6. #6
    Kris
    Guest

    Re: Data validation and empty cells

    Jim Thomlinson wrote:
    > Oops... For the life of me I thought you could use non-contiguious ranges in
    > validation arguments... Should have tested it all the way. Give this a try...
    >


    Thanks everybody.
    I could sort data to have empty cells at the end and this formula as a
    source works perfect

    =OFFSET($A$1,,,COUNTA($A$1:$A$7),1)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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