Excel VBA - Find value in external workbook, same folder

H

hunter.rogers

For any Cost Code there is a related Group code.
I am trying to populate the GroupCode Field in ThisWorkbook.worksheet1
by using a FIND CostCode from another workbook same folder.

Dim fso As Object, Source As Object, WS1 As Object, WS2 As Object
Dim GroupCode As String
Dim StartRow As Integer ' Destination WorkSheet Start Row

Set fso = CreateObject("Scripting.FileSystemObject")

Set Source = fso.GetFolder("P:\Test")
Set WS1 = ThisWorkbook.Sheets(1)
Set WS2 = "Group.xls"
Application.ScreenUpdating = False

Workbooks.Open Filename:=WS2.Path

Range("E2").Select
R1 = 2
Do While ActiveCell.Value <> ""
'The Group Workbook Sheet1 is structured as Column A for CostCode,
column B for GroupCode.
' I need help with this syntax
GroupCode= WorksheetFunction.Find(WS2.Sheet1,Range("A1:B10"),
ActiveCell)
WS1.Cells(R1, 14).Value = Group
StartRow = StartRow + 1
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True
End Sub
Thank you for your help,
Hunter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top