Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Get rid of empty cells when displaying Data validation list | Excel Discussion (Misc queries) | |||
Data validation and empty cells | Excel Discussion (Misc queries) | |||
Data Validation and Empty Row | Excel Discussion (Misc queries) | |||
Empty Cells in validation List | Excel Worksheet Functions | |||
Validation List with Variable Lengths & Invisible Empty Cells | Excel Programming |