ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel VBA - Find value in external workbook, same folder (https://www.excelbanter.com/excel-programming/411795-excel-vba-find-value-external-workbook-same-folder.html)

[email protected]

Excel VBA - Find value in external workbook, same folder
 
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


All times are GMT +1. The time now is 02:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com