Forum Discussion

Sparke0930's avatar
Sparke0930
Copper Contributor
Dec 22, 2018

I need to write a Macro that when run will hide rows

I am creating an order form for a small business.  The form has all of the items available to purchase.  When an employee works on an order for a customer, they will put a quantity in the "Quantity" cell. 

 

I want the macro to hide any row that has a quantity of "0".

 

This is my first attempt at writing Macros, so please be very specific.  The screen shot is of the order form as it is currently designed.

2 Replies

  • Hi,

     

    I have non-macro solution for your, I would suggest you convert that entry data into Excel Tables & insert the slicer for qty. When generating invoice select all and once you are done with your entry filter out the qty 0 unselect it.

     

    Hope you find this solution helpful and easy.

     

    Regards, Faraz Shaikh 

    • JWR1138's avatar
      JWR1138
      Iron Contributor

      Hi, If you are still looking for a VBA solution, just change "For i = 17 To 27" to the appropriate row numbers for your range that you want to hide row with a 0 in column J. 

       

       

      Sub HideRows()

      Dim i As Integer

      For i = 17 To 27

      If Cells(i, 10).Value = 0 Then

      Rows(i).EntireRow.Hidden = True

      End If

      Next i

      End Sub

      Sub UnHideRows()

      Rows.EntireRow.Hidden = False

      End Sub 

       

Resources