Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Data validation and empty cells


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


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

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Data validation and empty cells

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

--
Regards,
Tom Ogilvy


"Kris" wrote in message
...

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


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

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default 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:=xlBetw een


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

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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" wrote in
message ...
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:=xlBetw een


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

Thanks



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default 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" wrote in
message ...
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:=xlBetw een


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

Thanks






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get rid of empty cells when displaying Data validation list mbeauchamp Excel Discussion (Misc queries) 6 October 5th 06 09:37 PM
Data validation and empty cells Kris Excel Discussion (Misc queries) 3 December 19th 05 10:38 PM
Data Validation and Empty Row mzafar Excel Discussion (Misc queries) 1 July 19th 05 03:36 PM
Empty Cells in validation List Jasper Excel Worksheet Functions 1 January 28th 05 01:09 PM
Validation List with Variable Lengths & Invisible Empty Cells RobPendulum Excel Programming 3 December 7th 03 01:30 PM


All times are GMT +1. The time now is 09:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"