Resetting value in a cell to zero if another cell in the same row is selected and changed by the user

Bobo509

New Member
Joined
Apr 9, 2017
Messages
2
I have a sheet where I want to calculate a price in a range of cells (i18:i26) when a percentage value is entered in range (b18:b26).

If the user then wishes to input a price in range (i18:i26) I want the value of the cell in column b of the same row to change to zero.

The code below calculates my price when percentage is entered in range ColumnB but I cannot get the percentage to change to zero if I manually input a price. This means that when I input a percentage in another row the price I just changed resets according to the formula.

Any suggestions as how to achieve this would be greatly appreciated!

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


If Intersect(Target, Range("b18:b26")) Is Nothing Then Exit Sub


Application.EnableEvents = False
ActiveSheet.Range("$i18:$i26").Formula = "=IF($b18>0,$g18-($g18*$b18),0)"
Application.EnableEvents = True


If Target.Cells = ("i18:i26") Then
       Target.Offset(0, -7).Value = 0
       End If


End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Bobo509, welcome.

Sorry just re-read post.
Will re-post solution shortly.
 
Last edited:
Upvote 0
Maybe like....

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


If Target.Cells.Count > 1 Then Exit Sub
'Entering percentage
If Not Intersect(Target, Range("b18:b26")) Is Nothing Then
Application.EnableEvents = False
Target.Offset(0, 7) = Target.Offset(0, 5) * (1 - Target)
Application.EnableEvents = True
Exit Sub
End If
'Entering base price
If Not Intersect(Target, Range("g18:g26")) Is Nothing Then
Application.EnableEvents = False
Target.Offset(0, 2) = Target * (1 - Target.Offset(0, -5))
Application.EnableEvents = True
Exit Sub
End If
'entering an override price
If Not Intersect(Target, Range("i18:i26")) Is Nothing Then
Application.EnableEvents = False
Target.Offset(0, -7) = 0
Application.EnableEvents = True
Exit Sub
End If






End Sub

Hope that helps.
 
Upvote 0
Thank you @Snakehips - this is exactly what I needed - much appreciated! As a newbie to VBA I was struggling - this will really help in my understanding and problem solving future issues.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,215,611
Messages
6,125,829
Members
449,266
Latest member
davinroach

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