1

マクロのコーディングは初めてで、簡単な質問がありました。私がやろうとしているのは、空のセルの前にあるすべてのデータ ポイントを選択し、最後のポイントの行インデックスを保存することです。たとえば、以下のコードでは、行 1 ~ 4 を選択し、保存される行インデックスは 4 です。これまでのところ、データ ポイントを選択する次のコードがあります。

Cells(2, 2).Select
Range(Selection, Selection.End(xlDown)).Select 

最後の行のインデックスを保存するだけです。サンプルデータ:

1. 342
2. 342
3. 324
4. 234
5. <This would be an empty cell>
6. 43242
7. 342
8. 32423
9. 4324
4

2 に答える 2

1

これを試して

LastRow = Cells(2, 2).End(xlDown).Row

範囲の選択に熱心な場合は、

LastRow = Selection.Row + Selection.Rows.Count - 1

範囲の選択はお勧めしませんが。代わりにこれを使用してください

Dim rng As Range
Set rng = Range(Cells(2, 2), Cells(2, 2).End(xlDown))
LastRow = rng.Row + rng.Rows.Count - 1
于 2012-07-29T00:54:50.593 に答える
0
' column = whatever column you're working with

For evalRows = 1 to Range(Selection, Selection.End(xlDown)).Row

  If IsEmpty(Cells(evalRows, column).Value) Then

    ' you can only refer to the previous row if you're not on the first row
    If evalRows = 1 then

      ' do nothing

    Else

      ' refer to previous row
      lastUsefulRow = Offset(evalRows - 1, column).Row

    End If

  End If

Next
于 2012-07-28T22:57:14.863 に答える