Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Can you hide and unhide rows with a macro based on content of colu

We have a worksheet that collects rows of information from another sheet. Is
there a way to write a macro that would hide (or unhide as new rows are
added) so when I print it only prints rows with data?

Here is our attempt, which hides the rows but will not unhide the rows when
new rows are added. Suggestions???

Private Sub Worksheet_Change(ByVal Target As Range)

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False

With ActiveSheet
For Each cell In Range("B6:B30,B38:B62")
If cell.Value = "" Then
cell.EntireRow.Hidden = True
ElseIf cell.Value 1 Then
cell.EntireRow.Hidden = False
End If
Next
End With

Application.ScreenUpdating = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Can you hide and unhide rows with a macro based on content of colu

The range of cells you're hiding are hard-coded. Once you change the range of
cells "Range("B6:B30,B38:B62")" to include the new rows, your code should
work.




"Husker87" wrote:

We have a worksheet that collects rows of information from another sheet. Is
there a way to write a macro that would hide (or unhide as new rows are
added) so when I print it only prints rows with data?

Here is our attempt, which hides the rows but will not unhide the rows when
new rows are added. Suggestions???

Private Sub Worksheet_Change(ByVal Target As Range)

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False

With ActiveSheet
For Each cell In Range("B6:B30,B38:B62")
If cell.Value = "" Then
cell.EntireRow.Hidden = True
ElseIf cell.Value 1 Then
cell.EntireRow.Hidden = False
End If
Next
End With

Application.ScreenUpdating = True
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Can you hide and unhide rows with a macro based on content of

Thanks for the reply€¦ when we input values in the rows within the range (say
row 21 or 22) the macro then hides all the blank rows. The problem comes
when we then enter information that populates into row 23 it does not unhide
row 23. Make sense or should I explain with a hard example? Thanks again
for helping€¦

"aushknotes" wrote:

The range of cells you're hiding are hard-coded. Once you change the range of
cells "Range("B6:B30,B38:B62")" to include the new rows, your code should
work.




"Husker87" wrote:

We have a worksheet that collects rows of information from another sheet. Is
there a way to write a macro that would hide (or unhide as new rows are
added) so when I print it only prints rows with data?

Here is our attempt, which hides the rows but will not unhide the rows when
new rows are added. Suggestions???

Private Sub Worksheet_Change(ByVal Target As Range)

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False

With ActiveSheet
For Each cell In Range("B6:B30,B38:B62")
If cell.Value = "" Then
cell.EntireRow.Hidden = True
ElseIf cell.Value 1 Then
cell.EntireRow.Hidden = False
End If
Next
End With

Application.ScreenUpdating = True
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Can you hide and unhide rows with a macro based on content of

Assuming you always insert new rows at the bottom of the worksheet (I.e.
right after your 2nd range of rows):

Private Sub Worksheet_Change(ByVal Target As Range)

Dim lLastRow As Long

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False

With ActiveSheet
lLastRow = ws.Cells(Rows.Count, "B").End(xlUp).Row

For Each cell In Range("B6:B30,B38:" & lLastRow)
If cell.Value = "" Then
cell.EntireRow.Hidden = True
ElseIf cell.Value 1 Then
cell.EntireRow.Hidden = False
End If
Next
End With

Application.ScreenUpdating = True
End Sub





"Husker87" wrote:

Thanks for the reply€¦ when we input values in the rows within the range (say
row 21 or 22) the macro then hides all the blank rows. The problem comes
when we then enter information that populates into row 23 it does not unhide
row 23. Make sense or should I explain with a hard example? Thanks again
for helping€¦

"aushknotes" wrote:

The range of cells you're hiding are hard-coded. Once you change the range of
cells "Range("B6:B30,B38:B62")" to include the new rows, your code should
work.




"Husker87" wrote:

We have a worksheet that collects rows of information from another sheet. Is
there a way to write a macro that would hide (or unhide as new rows are
added) so when I print it only prints rows with data?

Here is our attempt, which hides the rows but will not unhide the rows when
new rows are added. Suggestions???

Private Sub Worksheet_Change(ByVal Target As Range)

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False

With ActiveSheet
For Each cell In Range("B6:B30,B38:B62")
If cell.Value = "" Then
cell.EntireRow.Hidden = True
ElseIf cell.Value 1 Then
cell.EntireRow.Hidden = False
End If
Next
End With

Application.ScreenUpdating = True
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Can you hide and unhide rows with a macro based on content of colu


Too quick when copy & paste. Try the following instead:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim oCell As Range
Dim lLastRow As Long


1 Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False

With ActiveSheet
lLastRow = .Cells(Rows.Count, "B").End(xlUp).Row

For Each oCell In .Range("B6:B30,B38:B" & lLastRow)
If oCell.Value = "" Then
oCell.EntireRow.Hidden = True
ElseIf oCell.Value 1 Then
oCell.EntireRow.Hidden = False
End If
Next
End With

Application.ScreenUpdating = True
End Sub






"Husker87" wrote:

We have a worksheet that collects rows of information from another sheet. Is
there a way to write a macro that would hide (or unhide as new rows are
added) so when I print it only prints rows with data?

Here is our attempt, which hides the rows but will not unhide the rows when
new rows are added. Suggestions???

Private Sub Worksheet_Change(ByVal Target As Range)

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False

With ActiveSheet
For Each cell In Range("B6:B30,B38:B62")
If cell.Value = "" Then
cell.EntireRow.Hidden = True
ElseIf cell.Value 1 Then
cell.EntireRow.Hidden = False
End If
Next
End With

Application.ScreenUpdating = True
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to hide/unhide WS based upon WS tab color Joe M. Excel Discussion (Misc queries) 1 April 8th 10 07:28 PM
Macro that will unhide then hide rows minka Excel Discussion (Misc queries) 10 October 21st 06 01:37 PM
Macro to hide and unhide based on criteria [email protected] Excel Discussion (Misc queries) 1 June 5th 06 08:05 PM
Hide/Delete entire rows based in the content of one cell Clueless Excel Discussion (Misc queries) 2 October 3rd 05 02:40 PM
Hide/unhide sheet macro based on cell calculation Greg Fisher Excel Programming 3 May 26th 05 05:58 PM


All times are GMT +1. The time now is 04:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"