Your macro can be shortened to:
Sub CommandButton1_Click()
Dim varBook As Variant
Dim otherWb As Workbook
varBook = Application.GetOpenFilename
If varBook <> False Then
Workbooks.OpenText Filename:=varBook
Set otherWb = ActiveWorkbook
'inserts values into designated cell
ThisWorkbook.Worksheets(2).Cells(1, 1).Value = otherWb.ActiveSheet.Cells(1, 1).Value
ThisWorkbook.Worksheets(2).Cells(1, 2).Value = otherWb.ActiveSheet.Cells(1, 2).Value
ThisWorkbook.Worksheets(2).Cells(1, 3).Value = otherWb.ActiveSheet.Cells(1, 3).Value
ThisWorkbook.Worksheets(2).Cells(6, 2).Value = otherWb.ActiveSheet.Cells(2, 2).Value
End If
End Sub
No need to store the locations of the values in the other workbook that you are looking for. A couple things I'd ask you:
Are there multiple worksheets in the workbook that is selected? Your code does not deal with sheets, so the active sheet will be where data is taken from.
I hate to ask, but are you sure you are looking for the data in cells A1, B1, C1, and B2?
Bookmarks