Topic: Help to understand an error in the code (excel vba)
Macro even in process, but I can not understand, in what now a problem. In a dialog box I take files different an ex-fur-tree, and glancing over them by turns I search for the information in them and I add on sheet shTotal. (In the future still it would be desirable that the data from each new book rushed in sample shTotal which at me in the code is added if there will be some books. Yet I do not know as it to implement)
Produces an error "subscript out of range", help to understand with it.
Sub Smeta () Dim oFD As FileDialog Dim sFolder $, Filename $, MyName $ Dim OutRow&, KolSmet& Dim sh As Worksheet Dim y, z, w As Range Dim cr, cr2, cr3 As Integer MyName = ThisWorkbook. Name Set oFD = Application. FileDialog (msoFileDialogFilePicker) With oFD .Title = "Nazvanie" .Filters. Add "Excel files", "*.xls *;*.xla *" .InitialFileName = ThisWorkbook. Path AND "\" If.Show = 0 Then Exit Sub Application. ScreenUpdating = False Application. DisplayAlerts = False Application. StatusBar = "Status......." For cr = 1 To oFD.SelectedItems. Count If cr <oFD.SelectedItems. Count Then Sheets (Sheets. Count).Copy after: = Sheets (Sheets. Count) sFolder =.SelectedItems (cr) Filename = Dir (sFolder, vbNormal) ' Workbooks ("Filename") whether.Activate--------- it is necessary generally here? For cr2 = 1 To Workbooks ("Filename").Worksheets (Sheets. Count)----------- Complains of this place and on similar further Set sh = Workbooks (Filename).Worksheets (cr2) Set y = sh. UsedRange. Find ("* (nevazhnochto)", LookIn: = xlValues, LookAt: = xlWhole, MatchCase: = False, SearchOrder: = xlByColumns) shTotal. Range ("R2") = y. Offset (2, 0) shTotal. Cells (4, 2).EntireRow. HorizontalAlignment = xlCenter Set z = sh. UsedRange. Find ("* (nevazhnochto) *", LookIn: = xlValues, LookAt: = xlWhole, MatchCase: = False, SearchOrder: = xlByColumns) shTotal. Cells (4, 3) = z. Offset (-1, 0) Set w = sh. UsedRange. Find ("* (nevazhnochto) *", LookIn: = xlValues, LookAt: = xlWhole, MatchCase: = False, SearchOrder: = xlByColumns) shTotal. Range ("R1") = w. Offset (-1, 0) Next cr2 Workbooks (Filename).Close KolSmet = KolSmet + 1 Filename = Dir () Next End With Application. ScreenUpdating = True Application. StatusBar = False MsgBox "Smet:" AND KolSmet Application. DisplayAlerts = True End Sub