主な目標は次のとおりです。列参照名を使用して、フィルタ処理された表の各行から特定のセル値を取得します。VBA:Range.Areaの各行からセル値を取得
これまでのところ、私は次のコード
Dim table As listObject
Dim columns As ListColumns
Dim row As ListRow
Dim rnData As range
Dim rngArea As range
Set table = Sheets(sheetName).ListObjects(TableName)
Set columns = table.ListColumns
Set rnData = ThisWorkbook.Worksheets(sheetName).ListObjects(TableName).range
'Notice that sheetName and TableName are function arguments. No need to pay attention. Consider any string values.
'Filter my table
table.range.AutoFilter Field:=7, Criteria1:=Array("filtervalue1", "filtervalue2"), Operator:=xlFilterValues
'Set the filtered table in a new Range object
Set rnData = ThisWorkbook.Worksheets(sheetName).ListObjects(TableName).range
'Count all rows of my filtered table
With rnData
For Each rngArea In .SpecialCells(xlCellTypeVisible).Areas
lCount = lCount + rngArea.Rows.Count
Next
End with
を持っている今、私はループに私のフィルタリングテーブル(私の「rnData」の範囲を)したいと私はそれらのRange.Areasの行ごとにセルの値を取得したいです。
私はこのような何かを考えていたが、私はこれを行うには、VBAで困難を抱えている:
For iRowNo = 2 To (lCount - 1) 'Start at 2 because 1 is the table header
'This does not work once it gets another row from the entire table. Not the filtered one. Help here!
Set row = table.ListRows(iRowNo)
'Something close to this - Help Here!
Set row = rnData.SpecialCells(xlCellTypeVisible).Areas
''Would like to have the code like this to get the values
cell1Value= row.range(1, columns("My Column Header 1").Index).value
cell2Value= row.range(1, columns("My Column Header 2").Index).Value
Next iRowNo
はこれより異なる解決策がある場合は、私に教えてください。
なぜ '各rngAreaについて...'ループは[それぞれのために '別の実行内部variable] in rngArea.rows' loop?この方法ですべての行を取得します(1つのセルに移動する場合は '[variable] .cells(1、y)'が必要なので、その制限内の行全体を参照していることに留意してください) –
命令不明(私の悪い英語のために申し訳ありません)、あなたはあなたが持っているものとあなたが望むものの写真を追加できますか?他の人にとってもより簡単になると思います。 – AntiDrondert
@DirkReichelそれを持ってきてくれてありがとう!それが問題を解決します。私は自分の質問に答えます。 –