Error 9, el subíndice está fuera del intervalo, código excel vba
Este código se me ha trabado:
Sub AbrirArchivos()
Dim Archivos As String
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
Dim dupes As Long
Dim maxDupes As Long
Dim dupeWord As String
Dim dupeTie As Boolean
Archivos = Dir("D:\Nueva carpeta\10 semana\*.xls")
Do While Archivos <> ""
Workbooks.Open "D:\Nueva carpeta\10 semana\" & Archivos
Set ws = ThisWorkbook.Sheets("F3") En esta parte sale el error 9
Set rng = ws.Range("x7:x32")
For Each cell In rng
dupes = Application.WorksheetFunction.CountIf(rng, cell)
If dupes > maxDupes Then
maxDupes = dupes
dupeWord = cell.Value
dupeTie = False
End If
If dupes = maxDupes And InStr(1, dupeWord, cell.Value) = False Then
dupeWord = dupeWord & ", " & cell.Value
dupeTie = True
End If
Next cell
If dupeTie = False Then MsgBox dupeWord & "" _
& "appears in the range " & maxDupes & " times."
If dupeTie = True Then MsgBox "The values (" & _
dupeWord & ") appear in the range " & maxDupes & " times."
Worksheets("F3").Cells(38, 24).Value = dupeWord
MsgBox ActiveWorkbook.Name
ActiveWorkbook.Close SaveChanges:=True
Archivos = Dir
Loop
End Sub