1

ユーザーが2つの連続しない列範囲を選択する状況では、次のように書きました:

Dim count long
Dim points variant
Dim i long

Set user_range = ActiveWindow.RangeSelection

count = user_range.count / 2

ReDim points(1 To count, 1 To 2)

For i = 1 To count

    MsgBox "value is" & user_range.Areas.Item(1).Value(i,1)

    points(i, 1) = user_range.Areas.Item(1).Value(i,1)

    points(i, 2) = user_range.Areas.Item(2).Value(i,1)


Next i

しかし、これを試すとオブジェクトエラーが発生します。値のインデックス付けが間違っていますか?

これは正しく動作するはずですか?これを行う簡単な方法はありますか?

どんな助けでも大歓迎です!

ありがとう、

ラス

4

1 に答える 1

1

残念ながら、あなたのコードはコンパイルされません。まず、変数を正しく宣言する必要があります。Option Explicitも使用する必要があります。

Option Explicit

Dim count As Long
Dim points As Variant
Dim i As Long
Dim user_range As Range

count 行と ReDim 行は問題ありませんが、2 つの選択が両方とも同じサイズであると想定しています。いつもそうなのだろうか?

user_range次に、何をしたいのかわかりませんが、値をに保存したいだけだと思いますpoints

少し異なる方法で対処する必要があります。

points(i, 1) = user_range.Areas(1).Cells(i, 1).Value    'Selection 1
points(i, 2) = user_range.Areas(2).Cells(i, 1).Value    'Selection 2
于 2012-09-21T21:30:55.310 に答える