Hello, I am currently in process of learning the VBA so please be gentle :D I have problem with "On error goto" statement inside looping. The aim is to categorize the movies on their length, create the sheet, name it after the category and copy the movies within the category to the new sheet. The first
"On Error GoTo Short1" works fine, but the second goto statement "On Error GoTo Medium1" fails to activate. Any suggestions? Thanks.
Code:
Code:
VBA Code:
Sub SimpleLoopIf()
Dim FilmLength As Integer
Dim FilmRating As String
Worksheets("Movie List").Activate
Range("A3").Select
GoTo 4
Short1:
Worksheets.Add
ActiveSheet.Name = "Short"
GoTo 4
Medium1:
Worksheets.Add
ActiveSheet.Name = "Medium"
GoTo 4
Long1:
Worksheets.Add
ActiveSheet.Name = "Long"
GoTo 4
4:
Do
FilmLength = ActiveCell.Offset(0, 3).Value
If FilmLength < 100 Then
FilmRating = "Short"
On Error GoTo Short1
Worksheets("Short").Activate
Worksheets("Movie List").Activate
ElseIf FilmLength < 150 Then
FilmRating = "Medium"
On Error GoTo Medium1
Worksheets("Medium").Activate
Worksheets("Movie List").Activate
Else
FilmRating = "Long"
On Error GoTo Long1
Worksheets("Long").Activate
Worksheets("Movie List").Activate
End If
Range(ActiveCell, ActiveCell.End(xlToRight)).Copy
Worksheets(FilmRating).Activate
ActiveCell.PasteSpecial
ActiveCell.Offset(1, 0).Select
Worksheets("Movie List").Activate
ActiveCell.Offset(0, 4).Value = FilmRating
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Value = ""
End Sub