View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
RyanH RyanH is offline
external usenet poster
 
Posts: 586
Default 2007 code not working in 2003

I don't see anything wrong. Where is the error occuring? I can point out a
few possibilities:

1.) Make sure your activecell is not is row 1. If it is then this line
will throw an error.

If ActiveCell.Offset(-1, 0).Value = "0" Then

The error occurs because there is not a Row 0.

2.) Make sure that all ModelSheet names are located in the workbook. For
example, make sure Sheets("Core Model"), Sheets("Model 1"), etc. are located
in the workbook.

3.) Make sure the Target cell is not the last cell at the very bottom of
the worksheet.

4.) Make sure that this code is not located in one of the Sheets in the
select case statement. This may cause an error, because it is continuing to
run the code to infiinite.

5.) I changed your code slightly:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim ModelSheet As String
Dim R As Long

Application.ScreenUpdating = False

' Setting value for string ModelSheet according to column of active cell
Select Case Target.Column
Case Is = 2
ModelSheet = "Core Model"
Case Is = 3
ModelSheet = "Model 1"
Case Is = 4
ModelSheet = "Model 2"
Case Is = 5
ModelSheet = "Model 3"
Case Is = 6
ModelSheet = "Model 4"
Case Is = 7
ModelSheet = "Model 5"
Case Is = 8
ModelSheet = "Model 6"
End Select

' Hidding or unhidding row where cell value is 0
R = Target.Row + 2

If Target.Offset(-1, 0).Value = 0 Then
Sheets(ModelSheet).Rows(R).Hidden = True
ElseIf Target.Offset(-1, 0).Value 0 Then
Sheets(ModelSheet).Rows(R).Hidden = False
End If

Application.ScreenUpdating = True

End Sub
--
Cheers,
Ryan


"Imran J Khan" wrote:

Hi,
I know there are plenty of posts with similar issues, but I have not been
able to find one that helps me. I don't know what part of the code below is
not compatible with 2003.


Private Sub Worksheet_Change(ByVal Target As Range)
Dim ModelSheet As String
Dim R As Long

Application.ScreenUpdating = False
'Setting value for string ModelSheet according to column of active cell
Select Case ActiveCell.Offset(-1, 0).Column
Case 2
ModelSheet = "Core Model"
Case 3
ModelSheet = "Model 1"
Case 4
ModelSheet = "Model 2"
Case 5
ModelSheet = "Model 3"
Case 6
ModelSheet = "Model 4"
Case 7
ModelSheet = "Model 5"
Case 8
ModelSheet = "Model 6"
End Select
'Hidding or unhidding row where cell value is 0
R = ActiveCell.Offset(2, 0).Row
If ActiveCell.Offset(-1, 0).Value = "0" Then
Worksheets(ModelSheet).Rows(R).Hidden = True
ElseIf ActiveCell.Offset(-1, 0).Value "0" Then
Worksheets(ModelSheet).Rows(R).Hidden = False
End If
Application.ScreenUpdating = True
End Sub

I would appreciate any input
Imran