Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Testing a cell

Hello group,

I am trying to detect if a cell is blank.
The Empty case always triggers correctly
but never the Full case when a cell has something in it.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target, Range("B1:B20")) Is Nothing Then
Select Case Target
Case IsEmpty("Target"): [D1] = "Empty"
Case Len("Target") 0: [D2] = "Full"
End Select
End If
End Sub

Any insight ?

Thanks,

Michael Singmin


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Testing a cell

Michael,

the problem is the quotes: you are testing the length of
the string "Target", rather than the length of the value
in the cell Target. Use:

Len(Target) or Len(Target.Value)

Alternatively, why not just use:

Case Else

Cheers, Pete

-----Original Message-----
Hello group,

I am trying to detect if a cell is blank.
The Empty case always triggers correctly
but never the Full case when a cell has something in it.

Private Sub Worksheet_SelectionChange(ByVal Target As

Range)
If Not Application.Intersect(Target, Range("B1:B20")) Is

Nothing Then
Select Case Target
Case IsEmpty("Target"): [D1] = "Empty"
Case Len("Target") 0: [D2] = "Full"
End Select
End If
End Sub

Any insight ?

Thanks,

Michael Singmin


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Testing a cell

Does this work??

Private Sub Worksheet_SelectionChange(ByVal Target As
Range)
If Not Application.Intersect(Target, Range("B1:B20")) Is
Nothing Then
Select Case Target
Case IsEmpty("Target"): [D1] = "Empty"
Case Not IsEmpty("Target"): [D2] = "Full"
End Select
End If
End Sub

-----Original Message-----
Hello group,

I am trying to detect if a cell is blank.
The Empty case always triggers correctly
but never the Full case when a cell has something in it.

Private Sub Worksheet_SelectionChange(ByVal Target As

Range)
If Not Application.Intersect(Target, Range("B1:B20")) Is

Nothing Then
Select Case Target
Case IsEmpty("Target"): [D1] = "Empty"
Case Len("Target") 0: [D2] = "Full"
End Select
End If
End Sub

Any insight ?

Thanks,

Michael Singmin


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Testing a cell

Hello Lars,

Unfortunately your code did not work.

Peter: Only Case Else works.

There seems to something strange with Target, it seems to degrade
after certain testing. In the Immediate window, I can validate all
the cells and their lengths. However in the VBE window, these values
seem to be become non existent.

Well, I can always fall back to Case Else.

Thanks for your suggestions,

Michael
================================================== ==========
"Lars Kofod" wrote:

Does this work??

Private Sub Worksheet_SelectionChange(ByVal Target As
Range)
If Not Application.Intersect(Target, Range("B1:B20")) Is
Nothing Then
Select Case Target
Case IsEmpty("Target"): [D1] = "Empty"
Case Not IsEmpty("Target"): [D2] = "Full"
End Select
End If
End Sub

-----Original Message-----
Hello group,

I am trying to detect if a cell is blank.
The Empty case always triggers correctly
but never the Full case when a cell has something in it.

Private Sub Worksheet_SelectionChange(ByVal Target As

Range)
If Not Application.Intersect(Target, Range("B1:B20")) Is

Nothing Then
Select Case Target
Case IsEmpty("Target"): [D1] = "Empty"
Case Len("Target") 0: [D2] = "Full"
End Select
End If
End Sub

Any insight ?

Thanks,

Michael Singmin


.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Testing a cell

How about:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target(1), Range("B1:B20")) Is Nothing Then
Select Case True
Case IsEmpty(Target(1).Value): Range("D1").Value = "Empty"
Case Len(Target(1).Value) 0: Range("d2").Value = "Full"
End Select
End If
End Sub

Watch your double quotes (mentioned before). But is there a reason you used
"select case" instead of a simple if/then?

And I used just the first cell in the Target.


Michael Singmin wrote:

Hello group,

I am trying to detect if a cell is blank.
The Empty case always triggers correctly
but never the Full case when a cell has something in it.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target, Range("B1:B20")) Is Nothing Then
Select Case Target
Case IsEmpty("Target"): [D1] = "Empty"
Case Len("Target") 0: [D2] = "Full"
End Select
End If
End Sub

Any insight ?

Thanks,

Michael Singmin


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Testing a cell

Well done Dave,

Something new to learn.

I am using Select Case because my application could have 12 different
values and types of values.

Thanks,

Michael

Dave Peterson wrote:

How about:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target(1), Range("B1:B20")) Is Nothing Then
Select Case True
Case IsEmpty(Target(1).Value): Range("D1").Value = "Empty"
Case Len(Target(1).Value) 0: Range("d2").Value = "Full"
End Select
End If
End Sub

Watch your double quotes (mentioned before). But is there a reason you used
"select case" instead of a simple if/then?

And I used just the first cell in the Target.


Michael Singmin wrote:

Hello group,

I am trying to detect if a cell is blank.
The Empty case always triggers correctly
but never the Full case when a cell has something in it.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target, Range("B1:B20")) Is Nothing Then
Select Case Target
Case IsEmpty("Target"): [D1] = "Empty"
Case Len("Target") 0: [D2] = "Full"
End Select
End If
End Sub

Any insight ?

Thanks,

Michael Singmin


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
testing for a value in a cell Dave Eade Excel Discussion (Misc queries) 1 February 11th 10 11:54 AM
Testing cell value for greater than 0 Raj[_2_] Excel Worksheet Functions 1 November 23rd 09 01:52 AM
Testing a cell value Finance Guru Excel Worksheet Functions 2 January 19th 09 12:44 PM
testing cell value Thompson, Joseph Excel Programming 1 November 8th 03 09:41 AM
testing the value of a cell Zeraia Excel Programming 3 October 22nd 03 12:58 AM


All times are GMT +1. The time now is 02:19 AM.

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"