J
John
Hello All, I want to be able to import data from two separate wookbooks with
very similar names into a third wookbook (named QIC_AM) which has all the
macros with a single click of the macro button. With the programming I have
now, the open dialogue box opens and I have to select the first individual
file and it copies all the data from the only sheet in the workbook and
pastes into QIC_AM onto sheet 1 named "items". Then the open dialogue box
opens again and I have to select the second workbook. This is copied into a
second worksheet in QIC_AM named "wires". Both 1st and 2nd workbooks will
then close. From there QIC_AM calculates various data.
Two individual workbooks will always be named similar. Examples are
1234-item.xls and 1234-wires.xls where the "-items.xls" and "-wires.xls" will
be constant.
How can I have Excel look for the "-wires.xls" that matches the first file
selected automatically? Below is the programming I have that I use today.
Dim Cell As Range
On Error GoTo errorhandler
Workbooks.Open Filename:=Dir(Application.GetOpenFilename), UpdateLinks:=0
Range("A1").Select
cellcheck = ActiveCell(1, 1)
If cellcheck <> "POS NBR" Then
Application.ScreenUpdating = True
MsgBox ("This File " & filetoopenitems & " Does Not Seem to be an
Item Chart, please check the file name and start again")
ActiveWorkbook.Close
ThisWorkbook.Activate
End
End If
Cells.Select
Selection.Copy
Windows("QIC_AM_r06 for GSD.xls").Activate
Sheets("Item Charts").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Cells.Select
Cells.EntireColumn.autofit
Range("A1").Select
Workbooks.Open Filename:=Dir(Application.GetOpenFilename), UpdateLinks:=0
Range("A1").Select
cellcheck = ActiveCell(1, 1)
If cellcheck <> "CIRCUIT NBR" Then
Application.ScreenUpdating = True
MsgBox ("This File " & filetoopenitems & " Does Not Seem to be a
Wire Chart, please check the file name and start again")
Dim WkbkName As Object
For Each WkbkName In Application.Workbooks()
If WkbkName.Name <> ThisWorkbook.Name Then WkbkName.Close
Next
ThisWorkbook.Activate
Selection.ClearContents
Range("A1").Select
End
End If
Cells.Select
Selection.Copy
Windows("QIC_AM_r06 for GSD.xls").Activate
Sheets("Wire Charts").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Cells.Select
Cells.EntireColumn.autofit
Range("A1").Select
For Each WkbkName In Application.Workbooks()
If WkbkName.Name <> ThisWorkbook.Name Then WkbkName.Close
Next
If Workbooks("QIC_AM_r06 for GSD.xls").Sheets("Wire Charts").Range("A2")
<> Workbooks("QIC_AM_r06 for GSD.xls").Sheets("Item Charts").Range("A2") Then
Application.ScreenUpdating = True
MsgBox ("These Files Do Not Seem to be the same harness assembly,
please check the file name and start again")
End
End If
Would appreciate any help anyone can give me.
very similar names into a third wookbook (named QIC_AM) which has all the
macros with a single click of the macro button. With the programming I have
now, the open dialogue box opens and I have to select the first individual
file and it copies all the data from the only sheet in the workbook and
pastes into QIC_AM onto sheet 1 named "items". Then the open dialogue box
opens again and I have to select the second workbook. This is copied into a
second worksheet in QIC_AM named "wires". Both 1st and 2nd workbooks will
then close. From there QIC_AM calculates various data.
Two individual workbooks will always be named similar. Examples are
1234-item.xls and 1234-wires.xls where the "-items.xls" and "-wires.xls" will
be constant.
How can I have Excel look for the "-wires.xls" that matches the first file
selected automatically? Below is the programming I have that I use today.
Dim Cell As Range
On Error GoTo errorhandler
Workbooks.Open Filename:=Dir(Application.GetOpenFilename), UpdateLinks:=0
Range("A1").Select
cellcheck = ActiveCell(1, 1)
If cellcheck <> "POS NBR" Then
Application.ScreenUpdating = True
MsgBox ("This File " & filetoopenitems & " Does Not Seem to be an
Item Chart, please check the file name and start again")
ActiveWorkbook.Close
ThisWorkbook.Activate
End
End If
Cells.Select
Selection.Copy
Windows("QIC_AM_r06 for GSD.xls").Activate
Sheets("Item Charts").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Cells.Select
Cells.EntireColumn.autofit
Range("A1").Select
Workbooks.Open Filename:=Dir(Application.GetOpenFilename), UpdateLinks:=0
Range("A1").Select
cellcheck = ActiveCell(1, 1)
If cellcheck <> "CIRCUIT NBR" Then
Application.ScreenUpdating = True
MsgBox ("This File " & filetoopenitems & " Does Not Seem to be a
Wire Chart, please check the file name and start again")
Dim WkbkName As Object
For Each WkbkName In Application.Workbooks()
If WkbkName.Name <> ThisWorkbook.Name Then WkbkName.Close
Next
ThisWorkbook.Activate
Selection.ClearContents
Range("A1").Select
End
End If
Cells.Select
Selection.Copy
Windows("QIC_AM_r06 for GSD.xls").Activate
Sheets("Wire Charts").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Cells.Select
Cells.EntireColumn.autofit
Range("A1").Select
For Each WkbkName In Application.Workbooks()
If WkbkName.Name <> ThisWorkbook.Name Then WkbkName.Close
Next
If Workbooks("QIC_AM_r06 for GSD.xls").Sheets("Wire Charts").Range("A2")
<> Workbooks("QIC_AM_r06 for GSD.xls").Sheets("Item Charts").Range("A2") Then
Application.ScreenUpdating = True
MsgBox ("These Files Do Not Seem to be the same harness assembly,
please check the file name and start again")
End
End If
Would appreciate any help anyone can give me.