2

I'm trying to access the values in C(Number):D(Number) inside the filtered list, however I seem to be doing something wrong because the MsgBox never shows up.

'Filter only numeric values 
With MaterialListSheet
        .AutoFilterMode = False
        .Range("B1").AutoFilter Field:=1, Criteria1:="0*"
    End With

Set rangeInventory = InventorySheet.Range("N1:N" & Rows.Count)
' I had Set rangeMaterialList = MaterialListSheet.Range("B1:B" & Rows.Count) in the beginning but I realized If I need C and D i'm only selecting B 

    Set rangeMaterialList = MaterialListSheet.Range("B1:F" & Rows.Count)

    For Each CellML In rangeMaterialList.SpecialCells(xlCellTypeVisible)
        BomCodesToSplit = CellML.Range("C" & Rows.Row & ":D" & Rows.Row).Values
        MsgBox BomCodesToSplit
        For Each CellI In rangeInventory.SpecialCells(xlCellTypeVisible)

        Next CellI

Next CellML

Tried this but no luck:

BomCodesToSplit = MaterialListSheet.Range("C" & Rows.Row & ":D" & Rows.Row).Values

I'd like to select

C1:D1
C2:D2
C3:D3
.
.
.

Meaning something like this so it selects it depending on the loop index

Cn:Dn

In some other programming languages I would use the index of the loop but since I'm new to VBA I have no idea how to do this.

How to achieve this?

4

1 回答 1

2

不完全确定您在做什么,但您可以使用迭代变量属性。

for each迭代某个范围的循环中,最好使用 Range 类型变量来获取智能感知

例子

Dim cell as Range
for each cell in Range("A1:A10")
    debug.? cell.Value, cell.Address, cell.Row, cell.Column
next

注意:当您键入时,cell.您会得到一个智能感知,它仅列出您正在使用的对象当前可用的属性。

于 2013-10-28T16:22:17.503 回答