Trying to create a Macro to put a zero in certain cells of the current row.

NickCourtney6

New Member
Joined
Sep 27, 2023
Messages
6
Office Version
  1. 365
Platform
  1. MacOS
Hello, I've tried this many different ways. I have in Column A a drop-down list of statuses:
Requested
Pending
Approved
Denied
Purchased
Received
Verified

StatusQuantity RequestedQuantity ApprovedGear NameUnit CostExt PriceOther CostsOther Costs PriceShipping CostsEstimated Purchase DateEstimated SubtotalLink
Requested22Blackmagic Decklink 8k Pro$745.00$1,490.00case$200.00$10.0010/1/23$1,700.00www.yahoo.com

When "Denied" is selected I want specific monetary cells within this row to equal zero but do not clear the content of the whole row. I would like to do this automatically once Denied is selected. However, if it must be a button, I'm okay with that too. Any help is greatly appreciated.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try this. Paste the VBA in the sheet module.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim KeyCells As Range
   Set KeyCells = Range("A:A") 
 
    If Not Application.Intersect(KeyCells, Target) Is Nothing Then
       If Target.Value = "Denied" Then
           Target.Offset(0, 4).Value = 0 ' Column E
           Target.Offset(0, 5).Value = 0 ' Column F
           Target.Offset(0, 7).Value = 0 ' Column H
           Target.Offset(0, 8).Value = 0 ' Column I
           Target.Offset(0, 10).Value = 0 ' Column K
       End If
   End If
End Sub
 
Upvote 0
This worked somewhat. However, the columns I would like to be zeroed out if Denied is selected are Columns B, C, E, H, J, and K.
 
Upvote 0
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim KeyCells As Range
   Set KeyCells = Range("A:A") 
 
    If Not Application.Intersect(KeyCells, Target) Is Nothing Then
       If Target.Value = "Denied" Then
           Target.Offset(0, 1).Value = 0 ' Column B
           Target.Offset(0, 2).Value = 0 ' Column C
           Target.Offset(0, 4).Value = 0 ' Column E
           Target.Offset(0, 7).Value = 0 ' Column H
           Target.Offset(0, 9).Value = 0 ' Column J
           Target.Offset(0, 10).Value = 0 ' Column K
       End If
   End If
End Sub
 
Upvote 0
Looks like it's due to a locked column with the sheet being protected. Any way around this?
 
Upvote 0
Disregard. At this time, I've got it sorted out. Thank you again for your knowledge and help!
 
Upvote 0

Forum statistics

Threads
1,215,105
Messages
6,123,114
Members
449,096
Latest member
provoking

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