使用EXCEL宏,VBA,找出整个sheet1中的所有绿色单元格,并读取每个单元格的值

不是读取每个单元格的值,而是读取出每个绿色单元格的位置,比如(1,“A”)

sub test()
dim jgarr(1 to 1000) as string
dim jgJs as integer
for each mycell in sheets(“sheet1”).cells
if mycell.font.color=? then '?绿色的色号 自己查一下
jgjs=jgjs+1
jgarr(jgjs)=mycell.text
endif
next mycell
'输出结果
sheets("sheet2").activate
for i=1 to jgjs
cells(i,1)=jgarr(i)
next i
end sub
随手写了一下,没有调试过
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-05-15
写好了,你可以参考追问

你好,可以发给我看一下吗?谢谢

第2个回答  2018-05-15
之前回答的,明天用电脑修改下代码。追问

能今天让我看下吗?比较急,谢谢

追答

上班后,马上帮你哈。
把Sheet1绿色单元格数据,获取到Sheet2表的A列
代码复制到Sheet1
Sub 获取绿色单元格地址()
Dim rng
For Each rng In Range("a1:z100")
If rng.Interior.ColorIndex = 10 Or rng.Interior.ColorIndex = 4 Then
N = N + 1
Sheets(2).Cells(N, 1) = rng.CurrentRegion.Address
End If
Next
Sheets(2).Select
End Sub

本回答被提问者采纳
相似回答