I am not very knowledgeable in coding. Just a marketing student trying to do some research.
I borrowed this code from the internet to collect data on movies. When I run the function, it shows me error 9 - subscript out of range (in bold - year = parts1(2)). I tried looking for answers and fiddled around but all in vain.
Any help will really be appreciated.
Option Explicit
Dim adjRev As Double
Dim rev As Double
Dim tickets As Long
Dim year As String
Dim rating As String
Dim genre As String
Dim director As String
Dim daysIn As Integer
Dim sDaysIn As String
Dim budnum As Double
Dim adjBud As Double
Dim budget As String
Dim runtime As String
Dim minutes As Integer
Dim x As Long
Dim y As Integer
Dim z As Integer
Dim address As String
Dim dist As String
Dim row As Long
Dim endRow As Long
Dim d As Date
Dim day As String
Dim date1 As String
Dim parts1() As String
Dim hours As Integer
Dim parts2() As String
Dim parts4() As String
Dim parsed As String
Dim page As String
Dim temp As String
Dim distParts() As String
Dim genreParts() As String
Dim ratingParts() As String
Dim budParts() As String
Dim tempDate As String
Dim dateParts() As String
Dim itemDate As String
Dim closeDay As Date
Dim monthNum As Integer
Dim startDay As Date
Dim tempParts() As String
Sub FillVariables()
Format
Scrape
Calculate
End Sub
Sub Format()
'Format all of the columns to the kind we need
Sheets("Movies A-Z").Activate
endRow = ActiveSheet.UsedRange.Rows.Count
ActiveSheet.Columns("A:O").NumberFormat = "General"
ActiveSheet.Columns(3).NumberFormat = "$#,##"
ActiveSheet.Columns(4).NumberFormat = "$#,##"
ActiveSheet.Columns(12).NumberFormat = "$#,##"
ActiveSheet.Columns(13).NumberFormat = "$#,##"
ActiveSheet.Columns(5).NumberFormat = "mm/dd/yyyy"
ActiveSheet.Range("A1:O1").NumberFormat = "General"
'Deletes all rows that start off with "n/a" in them - they're likely to have too little info
For row = 2 To endRow
For x = 1 To 5
If Cells(row, x).Value = "n/a" Then
Cells(row, x).EntireRow.Delete
x = 1
End If
DoEvents
Next
Next
endRow = ActiveSheet.UsedRange.Rows.Count
'Finds the day of the week and year that movies were released on
For row = 2 To endRow
d = Cells(row, 5).Value
day = WeekdayName(Weekday(d))
Cells(row, 11).Value = day
date1 = Cells(row, 5).Value
parts1 = Split(date1, "/")
year = parts1(2)
monthNum = parts1(0)
Cells(row, 15).Value = monthNum
Cells(row, 6).Value = year
Next
End Sub
I borrowed this code from the internet to collect data on movies. When I run the function, it shows me error 9 - subscript out of range (in bold - year = parts1(2)). I tried looking for answers and fiddled around but all in vain.
Any help will really be appreciated.
Option Explicit
Dim adjRev As Double
Dim rev As Double
Dim tickets As Long
Dim year As String
Dim rating As String
Dim genre As String
Dim director As String
Dim daysIn As Integer
Dim sDaysIn As String
Dim budnum As Double
Dim adjBud As Double
Dim budget As String
Dim runtime As String
Dim minutes As Integer
Dim x As Long
Dim y As Integer
Dim z As Integer
Dim address As String
Dim dist As String
Dim row As Long
Dim endRow As Long
Dim d As Date
Dim day As String
Dim date1 As String
Dim parts1() As String
Dim hours As Integer
Dim parts2() As String
Dim parts4() As String
Dim parsed As String
Dim page As String
Dim temp As String
Dim distParts() As String
Dim genreParts() As String
Dim ratingParts() As String
Dim budParts() As String
Dim tempDate As String
Dim dateParts() As String
Dim itemDate As String
Dim closeDay As Date
Dim monthNum As Integer
Dim startDay As Date
Dim tempParts() As String
Sub FillVariables()
Format
Scrape
Calculate
End Sub
Sub Format()
'Format all of the columns to the kind we need
Sheets("Movies A-Z").Activate
endRow = ActiveSheet.UsedRange.Rows.Count
ActiveSheet.Columns("A:O").NumberFormat = "General"
ActiveSheet.Columns(3).NumberFormat = "$#,##"
ActiveSheet.Columns(4).NumberFormat = "$#,##"
ActiveSheet.Columns(12).NumberFormat = "$#,##"
ActiveSheet.Columns(13).NumberFormat = "$#,##"
ActiveSheet.Columns(5).NumberFormat = "mm/dd/yyyy"
ActiveSheet.Range("A1:O1").NumberFormat = "General"
'Deletes all rows that start off with "n/a" in them - they're likely to have too little info
For row = 2 To endRow
For x = 1 To 5
If Cells(row, x).Value = "n/a" Then
Cells(row, x).EntireRow.Delete
x = 1
End If
DoEvents
Next
Next
endRow = ActiveSheet.UsedRange.Rows.Count
'Finds the day of the week and year that movies were released on
For row = 2 To endRow
d = Cells(row, 5).Value
day = WeekdayName(Weekday(d))
Cells(row, 11).Value = day
date1 = Cells(row, 5).Value
parts1 = Split(date1, "/")
year = parts1(2)
monthNum = parts1(0)
Cells(row, 15).Value = monthNum
Cells(row, 6).Value = year
Next
End Sub