- 最後登錄
- 2025-2-12
- 在線時間
- 49 小時
- 註冊時間
- 2007-11-16
- 閱讀權限
- 20
- 精華
- 0
- UID
- 2789285

- 帖子
- 66
- 積分
- 91 點
- 潛水值
- 17717 米
| tryit244178 發表於 2017-2-9 10:02 AM
再加入這個函式
然後把 If i.Interior.Color = Transparent Then
換成 If ComparisonData(i.value, "K2:V23 ... - Option Explicit
- Private Function ComparisonData(ByVal value As String, ByVal comparisonRange As String) As Boolean
- Dim i As Range
- ComparisonData = True
- For Each i In Sheet1.Range(comparisonRange)
- If value = i.value Then
- ComparisonData = False
- Exit For
- End If
- Next i
- End Function
- Private Sub CopyTransparentCell(ByVal seachRange As String)
- Dim i As Range
- Dim offestColumn As Integer
- For Each i In Sheet1.Range(seachRange)
- If ComparisonData(i.value, "K2:V23") Then
- offestColumn = i.column - 2
- 工作表1.Cells(GetLastRow(offestColumn), offestColumn).value = Sheet1.Range("B" & i.Row).value
- End If
- Next i
- End Sub
- Private Function GetLastRow(ByVal column As Integer) As Integer
- GetLastRow = 工作表1.Cells(工作表1.Cells.Rows.Count, column).End(xlUp).Row + 1
- End Function
- Sub ex()
- Dim A As Range, A_Po As String
- Dim AA As Range, Sh As Worksheet
- With Application.FindFormat
- .Clear
- .Interior.Color = vbBlack '設定儲存格圖樣顏色
- .Interior.ColorIndex = 1 '設定儲存格圖樣顏色
- End With
- Set Sh = Sheet1
- Set A = Sh.Cells.Find("", AFTER:=Sh.Cells(Sh.Cells(1).Count), SearchFormat:=True)
- Do While Not A Is Nothing
- If A_Po = "" Then
- A_Po = A.Address
- Set AA = A
- End If
- Set AA = Union(AA, A)
- Set A = Sh.Cells.Find(What:="", AFTER:=A, SearchFormat:=True)
- If A_Po = A.Address Then Exit Do
- Loop
- CopyTransparentCell "C2:J26"
- End Sub
複製代碼 目前的寫法修正如下,
但似乎還是無法達成,
現在連手動將格子填滿還是會抓到全部的資料,
不像之前還能挑出。
是上述的程式順序要更換嗎?
另外,- CopyTransparentCell "C2:J26"
複製代碼 是要放在哪裡呢?
如果放在最後的話,
excel會出現編譯錯誤,只有註解可以放在endsub.end function.或end property後面,
所以我才會放在ex()裡面,
還是我放錯位置導致無法順利執行?
以上兩個問題再麻煩你了。... |
|