![]() |
Hiding Rows in Excel with VBA
I am not sure if this requires VBA but I am working in Excel 2K and we need some simple code that (1) will hide a row if a zero appears in the column J of that row. Or alternatively (2 and to attach it to a button to be activated, code that will hide any row in a table range that shows a zero in column J for the range of the table (let's say from Rows A1:J25). If both of these are possible I would like to see sample code that would accomplish this. Can anyone help us get started? - we know how to write the code for the rest of our steps. This one has us a bit stuck.
Thanks! Dave |
Hiding Rows in Excel with VBA
David
Right-click on the sheet in which you want this to run and select the View Code option from the pop-up menu. Paste in the following code Presumably you will want to unhide the rows prior to updating the sheet. Sub UnhideRows() Dim rng As Range Set rng = Range("J1:J25") 'Make sure that nothing is hidden rng.Select Selection.EntireRow.Hidden = False End Sub Sub HideRows() Dim rng As Range Set rng = Range("J1:J25") 'Make sure that nothing is hidden rng.Select Selection.EntireRow.Hidden = False For Each c In rng c.Select If c.Value = 0 Then Selection.EntireRow.Hidden = True Else Selection.EntireRow.Hidden = False End If Next c End Sub -----Original Message----- I am not sure if this requires VBA but I am working in Excel 2K and we need some simple code that (1) will hide a row if a zero appears in the column J of that row. Or alternatively (2 and to attach it to a button to be activated, code that will hide any row in a table range that shows a zero in column J for the range of the table (let's say from Rows A1:J25). If both of these are possible I would like to see sample code that would accomplish this. Can anyone help us get started? - we know how to write the code for the rest of our steps. This one has us a bit stuck. Thanks! Dave |
Hiding Rows in Excel with VBA
Dim cell as Range
Range("1:25").EntireRow.Hidden = False for each cell in Range("J1:J25") if isnumeric(cell) and not isempty(cell) then if cell.Value = 0 then cell.Entirerow.Hidden = True end if end if Next Dim rng as Range set rng = Cells(ActiveCell.Row,"J") if isnumeric(rng) and not isempty(rng) then if rng.value = 0 then rng.Entirerow.Hidden = True end if end if -- Regards, Tom Ogilvy David Spiteri wrote in message ... I am not sure if this requires VBA but I am working in Excel 2K and we need some simple code that (1) will hide a row if a zero appears in the column J of that row. Or alternatively (2 and to attach it to a button to be activated, code that will hide any row in a table range that shows a zero in column J for the range of the table (let's say from Rows A1:J25). If both of these are possible I would like to see sample code that would accomplish this. Can anyone help us get started? - we know how to write the code for the rest of our steps. This one has us a bit stuck. Thanks! Dave |
All times are GMT +1. The time now is 05:20 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com