Lonemascot
New Member
- Joined
- Apr 28, 2015
- Messages
- 14
2 part question
Q1) I have sheet which is made up of pricing elements of a job. If an element is priced at £0 then then it doesn't need to appear on the report and I'd like to collapse the group automatically as opposed to clicking each one individually before printing.
I've used the following code: (where D21 is the price total and rows 9:20 are the details of the element being priced.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("$d1:d700")) Is Nothing Then
If Range("d21").Value = 0 Then
Rows("9:20").EntireRow.Hidden = True
Else
Rows("9:20").EntireRow.Hidden = False
End If
End If
End Sub
This works lovely until I insert an additional row within the range and the VBA code doesn't update to match the new range.
Is there a way to either do this within Excel as part of the grouping function or use a different VBA code to take account for inserting additional rows within the range?
Q2) How do I set page breaks to only break at the end of a group rather than in the middle of it? I looked at the subtotal function but seeing as my data isn't in a format where there are column headings I can't see how I could get that to work.
Q1) I have sheet which is made up of pricing elements of a job. If an element is priced at £0 then then it doesn't need to appear on the report and I'd like to collapse the group automatically as opposed to clicking each one individually before printing.
I've used the following code: (where D21 is the price total and rows 9:20 are the details of the element being priced.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("$d1:d700")) Is Nothing Then
If Range("d21").Value = 0 Then
Rows("9:20").EntireRow.Hidden = True
Else
Rows("9:20").EntireRow.Hidden = False
End If
End If
End Sub
This works lovely until I insert an additional row within the range and the VBA code doesn't update to match the new range.
Is there a way to either do this within Excel as part of the grouping function or use a different VBA code to take account for inserting additional rows within the range?
Q2) How do I set page breaks to only break at the end of a group rather than in the middle of it? I looked at the subtotal function but seeing as my data isn't in a format where there are column headings I can't see how I could get that to work.