首页 文章

Excel vba从数组中获取单元格位置

提问于
浏览
0

enter image description here

你好

我想循环遍历源范围并从源数组中拾取实际单元格位置,并在目标范围上应用条件格式化,每个单元格引用源范围中的唯一单元格 . Plase查看图片进行说明 .

因此,而不是从范围“A2:C3”获取“A2”(例如“1”)中的值 . 我喜欢获得“Sheet1!A2”..B2等的位置优秀 Value .

'高级方法

Sub setcondformat()

Dim sourcearr ??, Dim destarr ??, Dim Strpos as String

Dim Strvalue as String ' not necessary, but interesting for educational purposes

For each cell in Source Array do

 select next cell in destination Array    ' eg Sheet2!"J2", "K2" etc ..

  Set conditional format value = Strpos     ' in cond format dialog eg "A2", "B2" etc..

   Next cell sourcearr

end loop


End sub

1 回答

  • 0

    因此,如果您真正想要做的就是返回For循环中当前所在单元格的地址,您可以编写如下内容:

    For Each cell In SourceArray
        MsgBox cell.Address
    Next
    

    显然,您希望将地址存储为变量,或者将数据存储到数组中以便稍后使用该地址 . 如果单元格当前循环遍历单元格 A1 ,则返回$ 1 $ . 如果您正在调用单元格值,如问题中所述,您将使用 cell.value 返回单元格中的实际可见值 . 如果这不是你想要的,请告诉我,我会尝试调整我的答案 .

相关问题