軟體: EXCEL
版本: 2010
檔案1 test.xlsm
檔案2 date.xls
以檔案1的欄位以搜尋的的方法來找尋是否有出現在檔案2
附上程式碼
Sub FindAddress()
Dim s As Integer
Dim r As Integer
Dim GCell, txt As Range
Dim MySheet As String
'路徑
MyPath = "d:\test\"
'檔案名稱
MyWB = "date.xls"
MySheet = ActiveSheet.Name
'關顯示開唯讀
Application.ScreenUpdating = False
Workbooks.Open Filename:=MyPath & MyWB, ReadOnly:=True
e = 5
For r = 17 To 36
i = r
Set txt = Cells(r, e)
Set GCell = ActiveSheet.Cells.Find(What:=txt)
If Not GCell Is Nothing Then
With ThisWorkbook.ActiveSheet.Range("f" & (i))
.Value = "ok"
End With
Else
With ThisWorkbook.ActiveSheet.Range("f" & (i))
.Value = "no"
End With
End If
Next r
'開顯示不存檔
ActiveWorkbook.Close savechanges:=False
Application.ScreenUpdating = True
End Sub
問題1:無法指定檔案1的欄位來做搜尋,他都會跳到檔案2欄位做為搜尋的條件
請問是我哪裡寫錯了嗎??
問題2:因為檔案2會以月份做為工作表,所以之後會輸入的工作表至少會有12頁,
這樣開檔搜尋之後又關檔效率會好嗎?
請各位多多指教~~~謝謝!!