返回列表 上一主題 發帖

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

本帖最後由 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

回復 10# Hsieh


    原來2003和2007還有這樣的分別啊!
對於我這樣的初學者來說,讓我有多學會一個知識!
真是多虧你的幫忙!^^

TOP

回復 5# oobird


    謝謝你的幫忙!

TOP

回復 7# linshin1999


    是ColorIndex 是6沒有錯!
   
    真心的謝謝你的幫忙!

TOP

回復 4# candy516

因為2007與2003對顏色的設定差別相當大
所以除非你是以儲存格格式做搜尋
若以colorindex值搜尋就會失去準確性
所以在妳另一帖中我以sheet1數據來搜尋會比較準確
學海無涯_不恥下問

TOP

回復 8# oobird


    謝了!!
V98

TOP

木工版主你好:有關 Interior.ColorIndex 那裡可以找到 List, 如果知道請告知,謝謝!!
linshin1999 發表於 2011-1-17 09:25



    For I = 1 To 56
Cells(I, 1).Interior.ColorIndex = I
Next
這樣跑一下就有了

TOP

回復 4# candy516


    candy妳好:首先妳要確定 ColorIndex 是不是木工版主所提供的 "6", 因為黃色有很多種黃,如果是在這裡出問題那可會讓妳白忙了,看了木工版主的程式應該没問題,我提供給妳的是已經知道儲存格的內容,所以用 "鴻海" 去找, 因為妳並没提供 ColorIndex 值, 妳也可以用木工版主的程式,然後將 ColorIndex 改一改試試看.
V98

TOP

木工版主你好:有關 Interior.ColorIndex 那裡可以找到 List, 如果知道請告知,謝謝!!
V98

TOP

Sub YY()
Application.FindFormat.Interior.ColorIndex = 6
With ActiveSheet
For i = 1 To .Columns.Count
Set c = .Columns(i).Find(What:="", After:=.Cells(65536, i), SearchDirection:=xlNext, SearchFormat:=True)
If Not c Is Nothing Then MsgBox c.Address
Next
End With
End Sub

TOP

        靜思自在 : 太陽光大、父母恩大、君子量大,小人氣大。
返回列表 上一主題