sunrisema98
New Member
- Joined
- Jan 1, 2019
- Messages
- 1
Hello, I'm having trouble with the code that I use to copy a specific cell of a sheet from multiple workbooks within a folder to the master sheet. The debug tool points at the line of "With .Worksheets("financial_report"). I'm not sure why? The code is below:
Code:
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">[COLOR=#101094][FONT=inherit]Sub[/FONT][/COLOR][COLOR=#303336][FONT=inherit] Macro1_Query[/FONT][/COLOR][COLOR=#303336][FONT=inherit]()[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Dim[/FONT][/COLOR][COLOR=#303336][FONT=inherit] wb [/FONT][/COLOR][COLOR=#101094][FONT=inherit]As[/FONT][/COLOR][COLOR=#303336][FONT=inherit] Workbook[/FONT][/COLOR][COLOR=#303336][FONT=inherit],[/FONT][/COLOR][COLOR=#303336][FONT=inherit] ws [/FONT][/COLOR][COLOR=#101094][FONT=inherit]As[/FONT][/COLOR][COLOR=#303336][FONT=inherit] Worksheet
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Set[/FONT][/COLOR][COLOR=#303336][FONT=inherit] fso [/FONT][/COLOR][COLOR=#303336][FONT=inherit]=[/FONT][/COLOR][COLOR=#303336][FONT=inherit] CreateObject[/FONT][/COLOR][COLOR=#303336][FONT=inherit]([/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]"Scripting.FileSystemObject"[/FONT][/COLOR][COLOR=#303336][FONT=inherit])[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Set[/FONT][/COLOR][COLOR=#303336][FONT=inherit] fldr [/FONT][/COLOR][COLOR=#303336][FONT=inherit]=[/FONT][/COLOR][COLOR=#303336][FONT=inherit] fso[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]GetFolder[/FONT][/COLOR][COLOR=#303336][FONT=inherit]([/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]"C:
y = ThisWorkbook.Sheets("[/FONT][/COLOR][COLOR=#303336][FONT=inherit]sheet1[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]").Cells(Rows.Count, 1).End(xlUp).Row + 1
For Each wbfile In fldr.Files
If fso.GetExtensionName(wbfile.Name) = "[/FONT][/COLOR][COLOR=#303336][FONT=inherit]xls[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]" Then
With Workbooks.Open(wbfile.Path)
With .Worksheets("[/FONT][/COLOR][COLOR=#303336][FONT=inherit]financial_report[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]")
wsLR = .Cells(.Rows.Count, 1).End(xlUp).Row
ThisWorkbook.Sheets("[/FONT][/COLOR][COLOR=#303336][FONT=inherit]sheet1[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]").Cells(y, 2) = .Cells(wsLR, 7).Value
End With
.Close savechanges:=False
End With
wb.Close
End if
Next wbfile
End sub[/FONT][/COLOR]</code>