Hi all.
Hoping this forum once again can help me, once again.
I have this code part of a big sheet, it works, if all row are visible, in the range. This is the first short code.
The range in question is "For Each Cell In Range("A686,A1572,A2297,A2617,A2987,A3257,A3710,A4270,A4669,A5469,A5939,A6269,A6589,A6959,A7219,A7599,A7929")"
But as you can see from the long code, I have other factors where the long code, hide rows, and once this happen the short code stop working.
Any suggestions ?
I tried to add this code
Rows("686,1572,2297,2617,2987,3257,3710,4270,4669,5469,5939,6269,6589,6959,7219,7599,7929").EntireRow.Hidden = False
Still got error when running.
Looking forward to your reply :-)
/ Kristian
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim row As Variant, hidrng As Range
Dim Cell As Range
ActiveSheet.ResetAllPageBreaks
For Each Cell In Range("A686,A1572,A2297,A2617,A2987,A3257,A3710,A4270,A4669,A5469,A5939,A6269,A6589,A6959,A7219,A7599,A7929")
If Cell.Value = 1 Then
Cell.PageBreak = xlPageBreakManual
ElseIf Cell.Value = "x" Then
Cell.PageBreak = xlPageBreakNone
End If
Next Cell
End sub
This is the full code
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim row As Variant, hidrng As Range
' Dim KSPW As String
' KSPW = "Password"
' ActiveSheet.Unprotect Password:=KSPW
' Ovf. fra Fxx antal af valgte forsikringer.
If Not Intersect(Target, Target.Parent.Range("A:A")) Is Nothing Then
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Rows("4:9999").Hidden = False
For Each row In ActiveSheet.UsedRange.Rows
If row.Cells(1, 1).Value = "x" Then
If hidrng Is Nothing Then Set hidrng = row Else Set hidrng = Union(hidrng, row)
End If
Next row
If Not hidrng Is Nothing Then hidrng.Rows.Hidden = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End If
' Hvis nej vises row ikk
If Not Intersect(Target, Target.Parent.Range("A:A")) Is Nothing Then
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Rows("4:9999").Hidden = False
For Each row In ActiveSheet.UsedRange.Rows
If row.Cells(1, 2).Value = "y" Then
If hidrng Is Nothing Then Set hidrng = row Else Set hidrng = Union(hidrng, row)
End If
Next row
If Not hidrng Is Nothing Then hidrng.Rows.Hidden = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End If
' Hvis b, vises ikke = ingen bemærkninger, kun fritekst.
If Not Intersect(Target, Target.Parent.Range("A:A")) Is Nothing Then
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Rows("1:9999").Hidden = False
For Each row In ActiveSheet.UsedRange.Rows
If row.Cells(1, 3).Value = "b" Then
If hidrng Is Nothing Then Set hidrng = row Else Set hidrng = Union(hidrng, row)
End If
Next row
If Not hidrng Is Nothing Then hidrng.Rows.Hidden = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End If
' Hvis e, vises fritekst og bemærkninger ikke.
If Not Intersect(Target, Target.Parent.Range("A:A")) Is Nothing Then
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Rows("4:9999").Hidden = False
For Each row In ActiveSheet.UsedRange.Rows
If row.Cells(1, 4).Value = "e" Then
If hidrng Is Nothing Then Set hidrng = row Else Set hidrng = Union(hidrng, row)
End If
Next row
If Not hidrng Is Nothing Then hidrng.Rows.Hidden = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End If
' Disse 3 virker.
Dim Cell As Range
ActiveSheet.ResetAllPageBreaks
For Each Cell In Range("A686,A1572,A2297,A2617,A2987,A3257,A3710,A4270,A4669,A5469,A5939,A6269,A6589,A6959,A7219,A7599,A7929")
Selection.EntireRow.Hidden = False
If Cell.Value = 1 Then
Cell.PageBreak = xlPageBreakManual
ElseIf Cell.Value = "x" Then
Cell.PageBreak = xlPageBreakNone
End If
Next Cell
' Ovf. fra Fxx antal af valgte forsikringer.
If Not Intersect(Target, Target.Parent.Range("A:A")) Is Nothing Then
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Rows("4:9999").Hidden = False
For Each row In ActiveSheet.UsedRange.Rows
If row.Cells(1, 1).Value = "x" Then
If hidrng Is Nothing Then Set hidrng = row Else Set hidrng = Union(hidrng, row)
End If
Next row
If Not hidrng Is Nothing Then hidrng.Rows.Hidden = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End If
' Hvis nej vises row ikk
If Not Intersect(Target, Target.Parent.Range("A:A")) Is Nothing Then
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Rows("4:9999").Hidden = False
For Each row In ActiveSheet.UsedRange.Rows
If row.Cells(1, 2).Value = "y" Then
If hidrng Is Nothing Then Set hidrng = row Else Set hidrng = Union(hidrng, row)
End If
Next row
If Not hidrng Is Nothing Then hidrng.Rows.Hidden = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End If
' Hvis b, vises ikke = ingen bemærkninger, kun fritekst.
If Not Intersect(Target, Target.Parent.Range("A:A")) Is Nothing Then
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Rows("1:9999").Hidden = False
For Each row In ActiveSheet.UsedRange.Rows
If row.Cells(1, 3).Value = "b" Then
If hidrng Is Nothing Then Set hidrng = row Else Set hidrng = Union(hidrng, row)
End If
Next row
If Not hidrng Is Nothing Then hidrng.Rows.Hidden = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End If
' Hvis e, vises fritekst og bemærkninger ikke.
If Not Intersect(Target, Target.Parent.Range("A:A")) Is Nothing Then
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.Rows("4:9999").Hidden = False
For Each row In ActiveSheet.UsedRange.Rows
If row.Cells(1, 4).Value = "e" Then
If hidrng Is Nothing Then Set hidrng = row Else Set hidrng = Union(hidrng, row)
End If
Next row
If Not hidrng Is Nothing Then hidrng.Rows.Hidden = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End If
End Sub