If col A <= 0 Then

wisewood

Board Regular
Joined
Nov 7, 2002
Messages
193
I am after a way, when the worksheet is changed, for VBA to check if column A on the row that was changed is <= 0 then set the value of column D to nothing, empty, blank ... "".

Can someone help me.

I have managed to do something with it, but it seems to check every row when something is changed, rather than just the row containing the cell that was altered.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

brian.wethington

Well-known Member
Joined
Jul 20, 2006
Messages
1,739
Are you trying to check A of the row and if it is less than or equal to 0 then make the column d of that row nothing?

You can do this using a Worksheet Event

Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

On Error Resume Next
Application.EnableEvents = False
If Target.Count > 1 Then Exit Sub
If Cells(Target.Row, 1).Value <= 0 Then
    Cells(Target.Row, 4).Value = vbNullString
End If
Application.EnableEvents = True

End Sub
This will need to be put in the sheet you will be using it on.
 
Upvote 0

wisewood

Board Regular
Joined
Nov 7, 2002
Messages
193
Yes, that's the code that i had myself.

However, it does seem to flicker the screen for a few seconds each time you change a cell, as though it is performing this check against every row.
 
Upvote 0

brian.wethington

Well-known Member
Joined
Jul 20, 2006
Messages
1,739
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False
If Target.Count > 1 Then Exit Sub
If Cells(Target.Row, 1).Value <= 0 Then
    Cells(Target.Row, 4).Value = vbNullString
End If
Application.ScreenUpdating = False
Application.EnableEvents = True

End Sub
This might fix a bit of the flicker as well.
 
Upvote 0

Forum statistics

Threads
1,191,204
Messages
5,985,278
Members
439,953
Latest member
suchitha

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
Top