I am trying to find a way to copy data from an excel workbook that is closed. The problem is one code I am using only applies if the data remains identical then i can set cell location. However, I am searching for a particular row that that finds value of "AM, BA, KO". These are under my "A" column while the data I want to extract is in the same row but in column "n"
I have been using this only for pulling information with the same set rows and columns every time. The problem I am coming up with this new report is that sometimes there are 70 rows then at other times there are 120 rows. But these values in "A" are present and the data I need is in "m"
Sub GetDataFromClosedWorkbook()
Dim wb As Workbook
Application.ScreenUpdating = False ' turn off the screen updating
Set wb = Workbooks.Open("C:\Foldername\Filename.xls", True, True)
' open the source workbook, read only
With ThisWorkbook.Worksheets("TargetSheetName")
' read data from the source workbook
.Range("A10").Formula = wb.Worksheets("SourceSheetName").Range("A10").Formula
.Range("A11").Formula = wb.Worksheets("SourceSheetName").Range("A20").Formula
.Range("A12").Formula = wb.Worksheets("SourceSheetName").Range("A30").Formula
.Range("A13").Formula = wb.Worksheets("SourceSheetName").Range("A40").Formula
End With
wb.Close False ' close the source workbook without saving any changes
Set wb = Nothing ' free memory
Application.ScreenUpdating = True ' turn on the screen updating
End Sub
</pre>
I have been using this only for pulling information with the same set rows and columns every time. The problem I am coming up with this new report is that sometimes there are 70 rows then at other times there are 120 rows. But these values in "A" are present and the data I need is in "m"
Sub GetDataFromClosedWorkbook()
Dim wb As Workbook
Application.ScreenUpdating = False ' turn off the screen updating
Set wb = Workbooks.Open("C:\Foldername\Filename.xls", True, True)
' open the source workbook, read only
With ThisWorkbook.Worksheets("TargetSheetName")
' read data from the source workbook
.Range("A10").Formula = wb.Worksheets("SourceSheetName").Range("A10").Formula
.Range("A11").Formula = wb.Worksheets("SourceSheetName").Range("A20").Formula
.Range("A12").Formula = wb.Worksheets("SourceSheetName").Range("A30").Formula
.Range("A13").Formula = wb.Worksheets("SourceSheetName").Range("A40").Formula
End With
wb.Close False ' close the source workbook without saving any changes
Set wb = Nothing ' free memory
Application.ScreenUpdating = True ' turn on the screen updating
End Sub
</pre>