Hiding rows macro

biglb79

Active Member
Joined
Oct 17, 2007
Messages
303
Office Version
  1. 2019
Platform
  1. Windows
is there a macro I can run that would hide any rows 2-200 if the amounts in columns F or G are zero?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi!

Modify it if needed:

Code:
Sub macro()


Dim i As Integer
Dim row As Long


row = Cells(Rows.Count, 1).End(xlUp).row


For i = 1 To row Step 1 'count rows in column "A"




    If Cells(i, "G").Value = 0 Then
     Rows(i).EntireRow.Hidden = True


    End If
    
    If Cells(i, "F").Value = 0 Then
     Rows(i).EntireRow.Hidden = True


    End If
    
    Next
    


    End Sub


is there a macro I can run that would hide any rows 2-200 if the amounts in columns F or G are zero?
 
Upvote 0
thanks, but a majority of the rows will have a value in columns F or G. I just want the rows that have zeros in both columns to hide
 
Upvote 0
You used "or" so don't be surprised at my code :D Next time if you use "and" i will understand what you want.

Try:


Code:
Sub macro()
 
 
Dim i As Integer
Dim row As Long
 
 
row = Cells(Rows.Count, 1).End(xlUp).row
 
 
For i = 1 To row Step 1 'count rows in column "A"
 
 
 
 
    If Cells(i, "G").Value = 0 and Cells(i, "F").Value = 0 Then
     Rows(i).EntireRow.Hidden = True
 
 
    End If
   
    Next
   
 
 
    End Sub
thanks, but a majority of the rows will have a value in columns F or G. I just want the rows that have zeros in both columns to hide
 
Upvote 0
sorry that's my bad. I do really appreciate your help. I didn't realize I worded it incorrectly until I used your code and figured out what was going on
 
Upvote 0
it does work great but for some reason the rows 63, 117 and 118 didn't hide. I wonder if it's a rounding issue
 
Upvote 0
I fixed it. I think it had something to do with what column G was registering. I appreciate your help!
 
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