返回列表 上一主題 發帖

請問:如何尋找黃色底色的儲存格?!

本帖最後由 FAlonso 於 2011-1-17 17:22 編輯

首先解決格子底色問題
用下列程式試試其顏色編號
  1. Sub abc()
  2. Dim i
  3. i = Sheet1.Range("A1").Interior.ColorIndex '修改目標地址
  4. MsgBox i
  5. End Sub
複製代碼
然後
  1. Option Explicit
  2. Sub choosesheet()
  3. Dim myyear As String, mystock As String
  4. Dim myfind As Range, myrange As Range, mycell As Range

  5. thisworkbook.activate

  6. myyear = Application.InputBox(myyear, "Enter year")

  7. If IsNumeric(myyear) Then
  8.     If myyear < 2001 Or myyear > 2010 Then
  9.     MsgBox "Out of Range"
  10.     Exit Sub
  11.     Else
  12.     Sheets(myyear).Activate
  13.     End If
  14. Else
  15. MsgBox "Not A Number"
  16. Exit Sub
  17. End If

  18. mystock = Application.InputBox(mystock, "Enter Stock Name")

  19. With Sheets(myyear)
  20. Set myfind = .Rows(1).Find(what:=mystock, after:=.[b1], lookat:=xlPart)
  21. If myfind Is Nothing Then
  22. MsgBox "No Findings"
  23. Else
  24. Set myrange = .Range(myfind, myfind.End(xlDown))

  25. For Each mycell In myrange
  26. If mycell.Interior.ColorIndex = 6 Then
  27. mycell.Activate
  28. Exit For
  29. End If
  30. Next

  31. End If
  32. End With
  33. End Sub
複製代碼
輸入年份及其股票代號或名稱,該程式便會去到指定黃式格子
請肯定每個column只有一個黃色格子而已,如果不是此程式需要作修改,類似findnext + loop xxxx<>xxx.address之類的
有問題再call我
80 字節以內
不支持自定義 Discuz! 代碼

TOP

回復  FAlonso


你好~
請問我執行完第一個程式碼他跑出的訊息是"4142"這是什麼意思?!
謝謝你的回答! ...
candy516 發表於 2011-1-17 18:05

指格子是"無填滿".即default的color index
該程式是偵察出黃色的編號,不用猜
我第二個程式,你覺得怎樣?
80 字節以內
不支持自定義 Discuz! 代碼

TOP

回復  FAlonso


喔~原來是這個意思呀!
第二個程式也很厲害耶!
大家都好厲害唷!
^^
candy516 發表於 2011-1-17 21:34

關於那個填權日數,我遲些寫一個程式給你
80 字節以內
不支持自定義 Discuz! 代碼

TOP

        靜思自在 : 信心、毅力、勇氣三者具備,則天下沒有做不成的事。
返回列表 上一主題