- 帖子
- 438
- 主題
- 67
- 精華
- 0
- 積分
- 531
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office 2010
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2012-10-30
- 最後登錄
- 2024-11-19
|
16#
發表於 2012-12-9 23:21
| 只看該作者
回復 4# GBKEE - ption Explicit
- Sub ex()
- Dim FRng As Range, Wb As Workbook
- Dim A As Range, Rng As Range
- Dim fs As String, xi As Integer
- fs = "C:\Documents and Settings\USER\桌面\payment report 2012.xlsx"
- Set Wb = Workbooks.Open(fs)
- Set FRng = Wb.Sheets("New form of payment report").Range("k:k").Find(Date, lookat:=xlWhole, SearchDirection:=xlPrevious) '在b.xlsx 的K欄尋找等當日的日期的一列
- If Not FRng Is Nothing Then '假如找到
- If FRng.Offset(, -3).Value >= 0.95 [color=Red]And FRng.Offset(, -3).Value <> " "[/color] Then '假如b.xlsx 這列的H欄的值大過或等於0.95
- Set Rng = Workbooks("outstanding payments").Sheets("outstanding payments").Range("a:a").Find(FRng.Offset(, -9), lookat:=xlWhole, SearchDirection:=xlPrevious) ' 在a.xlsx 的A欄尋找b.xlsx 這列的B欄的值是否存在
- [color=Red]If Rng Is Nothing Then [/color]'假如找不到
- [color=Red]With Workbooks("outstanding payments").[/color]Sheets("outstanding payments") ' 在a.xlsx 的A欄最後一列加上b.xlsx 這列的B欄的值,及 在a.xlsx 的F欄最後一列加上b.xlsx 這列的K欄的值
- xi = .UsedRange.Cells(.UsedRange.Count).Row
- .UsedRange.Cells(xi, "A") = FRng.Offset(, -9).Value
- .UsedRange.Cells(xi, "F") = FRng.Value
-
- End With
- End If
-
- End If
- End If
- Wb.Close 0
- End Sub
複製代碼 之前If Rng Is Nothing Then 寫錯成 If FRng Is Nothing Then ,但是改完了也沒有反應,只是打開另一個excel後就沒有什麼反應,是哪裡出現問題了,請指定迷津。 不管最後一列是否H欄是否空格或者百份之幾都沒有反應,另外 Set FRng = Wb.Sheets("New form of payment report").Range("k:k").Find(Date, lookat:=xlWhole, SearchDirection:=xlPrevious) 是否會不停地往上尋找,直到第一列為止? |
|