inexplicable 0

ndendrinos

Well-known Member
Joined
Jan 17, 2003
Messages
1,694
this is a sheet change event that does the following:
So as I type starting in A17
If value in column B is less than the value in column A then the difference is shown in column C
And it works perfect like this:

A17=5...B17=5...C17...s/b empty
A18=8...B18=8...C18...s/b empty
A19=3...B19=3...C19...s/b empty
A20=7...B20=6...C20...s/b 1

EXCEPT that in C17 I get 0 (zero) instead of an empty cell (all the rest of the "empty" are indeed empty without a zero)

Well that zero in C17 has to go for it interferes with my other code

Many thanks



Code:
'If Not Intersect(Target, Range("B17:B35")) Is Nothing Then
   ' x = Target.Row
    'Cells(x, 3) = Cells(x, 1) - Cells(x, 2)
'End If

P.S all cells in C17:C35 are formatted general
 
Last edited:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
can't you just test if the subtraction is 0 first to get around this? I am surprised the other values are really empty and not 0..

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B17:B35")) Is Nothing Then
    x = Target.Row
    If Cells(x, 1) - Cells(x, 2) = 0 Then
        Cells(x, 3) = ""
    Else: Cells(x, 3) = Cells(x, 1) - Cells(x, 2)
    End If
End If
End Sub
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B17:B35")) Is Nothing Then
        x = Target.Row
        If Cells(x, 1) > Cells(x, 2) Then
            Cells(x, 3) = Cells(x, 1) - Cells(x, 2)
        Else
            Cells(x, 3).ClearContents
        End If
    End If
End Sub
 
Upvote 0
and yet they are empty tfaulkes but your code took care of my problem
so is your solution AlphaFrog

So now I have a bigger problem than initially and that is witch of the two codes to use.
(joking) Thank you both for your responses
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,908
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top