
Originally Posted by
russ50
Thanks for information, I did notice several instances of excel open and tried to correct with Application.Quit. Fairly new with VBA and still learning.
This should open your inventory workbook in the same Excel instance.
Sub Test()
Dim MyName As String
Dim xlBook As Workbook
Dim oRange As Range
Dim wsDest As Worksheet
Set wsDest = ActiveSheet
MyName = ????
Application.ScreenUpdating = False
Set xlBook = Workbooks.Open("c:\temp\inventory.xlsx")
Set oRange = xlBook.Worksheets("Sheet1").Columns(1)
Set aCell = oRange.Find(What:=MyName, LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If Not aCell Is Nothing Then
firstName = aCell.Address
Do
nextRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Row + 1
aCell.Resize(, 4).Copy
wsDest.Cells(nextRow, 1).PasteSpecial Paste:=xlValues
Set aCell = oRange.FindNext(aCell)
Loop While Not aCell Is Nothing And aCell.Address <> firstName
End If
Application.CutCopyMode = False
xlBook.Close SaveChanges:=False 'close inventory workbook
Application.ScreenUpdating = True
End Sub
Bookmarks