Using VBA to set cell values based on values in the same row

Swagner

New Member
Joined
Jan 2, 2019
Messages
6
Hey guys, need a little help here.

I'm working on a proposal sheet for a business and I want to add a button on the top that would let them reset the quantities all to 0. I have a "Description" column that has values such as header, product, description, and subtotal. Basically what I need is some VBA to set each row's quantity value to 0 if the "Description" column = product.

I've tried some things, but just can't get it to work.

Thanks all!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi & welcome to MrExcel.
A few questions
1) What column is the Description column?
2) What columns do you want setting to 0?
3) Do you have the Headers in row 1 with data starting in row2?
4) Are the Quantities values, or the result of formulae?
 
Upvote 0
1) The description column is titled "Formatting" and it is in column D
2) "Quantity" column is in column I
3) Headers start on row 51 (Quote info is above)
4) Quantities are all values, no formulas

Thanks!
 
Upvote 0
Ok, try
Code:
Sub Swagner()
   Dim Lr As Long
   Lr = Range("D" & Rows.Count).End(xlUp).Row
   Range("D51:D" & Lr).AutoFilter 1, "Product"
   Range("I52:I" & Lr).Value = 0
   ActiveSheet.AutoFilterMode = False
End Sub
 
Upvote 0
If you step through the code using F8, when this line is highlighted
Code:
Range("I52:I" & Lr).Value = 0
have a look at the sheet, is it filtered correctly?
 
Upvote 0
Ohhh, I think I see what's happening.

Column A is a hidden column that controls the filtering (if the quantity = 0, then value = hide, if quantity <0 then value = display). After the quote is created then the table auto-filters to only show rows that contain "Display" in that column.

Hope that makes sense. If this can't work that's fine. i'll just name the range and remember to update the range as we add new products.
 
Upvote 0
Do you want to remove the filter on col A, to then clear the values for "Products"?
 
Upvote 0
Yup, what's the last col in row 51?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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