シート内のすべての非表示および空白以外の行をループしようとしています。問題は、非表示のシートをループしますが、非表示のシートの最後に到達すると、永遠に続きます。
フィルターの後に147行(非表示の行を含む)を取得し、ループを実行するときにそれらをスキップすることを知っていますが、147で完了した後、148に続くなど、取得したものかどうかを確認する検証がありますは空白で、そこで止まります。147 で停止するか、フィルターをスローする任意の数の行で停止したいと思います。
私がやっていること:
'I need the cells in B1 to begin with 0 or W, I guess I'd have to add a non-blank option (see below)
With MaterialListSheet
.AutoFilterMode = False
.Range("B1").AutoFilter Field:=1, Criteria1:="0*", Operator:=xlOr, Criteria2:="W*"
End With
Set rangeMaterialList = MaterialListSheet.Range("B2:B" & Rows.Count)
For Each CellML In rangeMaterialList.SpecialCells(xlCellTypeVisible)
'Reset the variable in order to avoid unwanted codes
BomCodesToSplit = ""
'Check if there's a code in the cell
If MaterialListSheet.Range("C" & CellML.Row & ":C" & CellML.Row).Value <> "" Then
BomCodesToSplit = MaterialListSheet.Range("C" & CellML.Row & ":C" & CellML.Row).Value
End If
'Check if theres a code in the cell AND if it does concatenate (in case the variable isn't empty)
If MaterialListSheet.Range("D" & CellML.Row & ":D" & CellML.Row).Value <> "" Then
If BomCodesToSplit <> "" Then
BomCodesToSplit = BomCodesToSplit & " / " & MaterialListSheet.Range("D" & CellML.Row & ":D" & CellML.Row).Value
Else
BomCodesToSplit = MaterialListSheet.Range("D" & CellML.Row & ":D" & CellML.Row).Value
End If
End If
'Check if any BomCodes were retrieved
If BomCodesToSplit = "" Then
MsgBox "There was an error getting the Bom Codes", vbCritical, "Execution Terminated"
End
Else
BomCodes = Split(BomCodesToSplit, "/")
End If
Next CellML
End Sub
私が試したフィルター:
'Im aware this doesn't work but decided to try it anyway
With MaterialListSheet
.AutoFilterMode = False
.Range("B1").AutoFilter Field:=1, Criteria1:="<>"
.Range("B1").AutoFilter Field:=1, Criteria1:="0*", Operator:=xlOr, Criteria2:="W*"
End With
'私もこれが不可能であることを認識しています (私は思う)
With MaterialListSheet
.AutoFilterMode = False
.Range("B1").AutoFilter Field:=1, Criteria1:="0*", Operator:=xlOr, Criteria2:="W*", Operator:=xlAnd, Criteria3:="<>"
End With
それがフィルターの問題なのか、それとも何かが足りないのかもわかりません。VBAは初めてで、まだ知らないことがたくさんあります。'Check if any BomCodes were retrieved
私が望むのは (この場合は 147 までループすることだけなので、コードには入りません 。