ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If Target="" error (https://www.excelbanter.com/excel-programming/281962-if-target%3D-error.html)

Otto Moehrbach[_5_]

If Target="" error
 
Excel 2002, Win XP
I have a short WorkSheet_Change macro as below:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("F29:J29", "F93")) Is Nothing Then Exit Sub
If Target = "" Then Exit Sub
'Call a macro
End Sub

I'm getting a Type Mismatch error on:
If Target = "" Then Exit Sub
and only the 'If Target="" Then' is highlighted

I think I've done this before without the error. Maybe I'm thinking of a
regular macro.
What I want to do is Exit Sub if Target is blank.
Where did I go wrong?
Thanks for your help. Otto



Tom Ogilvy

If Target="" error
 
Either:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.count 1 then exit sub
If Intersect(Target, Range("F29:J29", "F93")) Is Nothing Then Exit Sub
If isempty(Target) Then Exit Sub
'Call a macro
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 then exit sub
If Intersect(Target, Range("F29:J29", "F93")) Is Nothing Then Exit Sub
If len(trim(Target)) = 0 Then Exit Sub
'Call a macro
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.count 1 then exit sub
If Intersect(Target, Range("F29:J29", "F93")) Is Nothing Then Exit Sub
If Target.Text = "" Then Exit Sub
'Call a macro
End Sub


If you want to process a multi cell area for Target, then you will have to
add code to specifically deal with that.

Range("A1").Resize(2,1) = ""

will raise a type mismatch error since you are comparing an array to a
string.

--
Regards,
Tom Ogilvy


Otto Moehrbach wrote in message
...
Excel 2002, Win XP
I have a short WorkSheet_Change macro as below:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("F29:J29", "F93")) Is Nothing Then Exit Sub
If Target = "" Then Exit Sub
'Call a macro
End Sub

I'm getting a Type Mismatch error on:
If Target = "" Then Exit Sub
and only the 'If Target="" Then' is highlighted

I think I've done this before without the error. Maybe I'm thinking of a
regular macro.
What I want to do is Exit Sub if Target is blank.
Where did I go wrong?
Thanks for your help. Otto





Otto Moehrbach[_5_]

If Target="" error
 
Tom
What you pointed out seems so obvious once I see it. Thanks for the
help, as always. Otto
"Tom Ogilvy" wrote in message
...
Either:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.count 1 then exit sub
If Intersect(Target, Range("F29:J29", "F93")) Is Nothing Then Exit Sub
If isempty(Target) Then Exit Sub
'Call a macro
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 then exit sub
If Intersect(Target, Range("F29:J29", "F93")) Is Nothing Then Exit Sub
If len(trim(Target)) = 0 Then Exit Sub
'Call a macro
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.count 1 then exit sub
If Intersect(Target, Range("F29:J29", "F93")) Is Nothing Then Exit Sub
If Target.Text = "" Then Exit Sub
'Call a macro
End Sub


If you want to process a multi cell area for Target, then you will have to
add code to specifically deal with that.

Range("A1").Resize(2,1) = ""

will raise a type mismatch error since you are comparing an array to a
string.

--
Regards,
Tom Ogilvy


Otto Moehrbach wrote in message
...
Excel 2002, Win XP
I have a short WorkSheet_Change macro as below:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("F29:J29", "F93")) Is Nothing Then Exit

Sub
If Target = "" Then Exit Sub
'Call a macro
End Sub

I'm getting a Type Mismatch error on:
If Target = "" Then Exit Sub
and only the 'If Target="" Then' is highlighted

I think I've done this before without the error. Maybe I'm thinking of

a
regular macro.
What I want to do is Exit Sub if Target is blank.
Where did I go wrong?
Thanks for your help. Otto








All times are GMT +1. The time now is 10:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com