1

In the situation where the user select two non-contiguous column ranges i wrote the following:

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

But i get an object error when i try this. Am i indexing Value wrong?

This should work right? Is there an easier way to do this?

Any help is greatly appreciated!

Thanks,

Russ

Olle Sjögren
  • 5,315
  • 3
  • 31
  • 51
Russ Urquhart
  • 327
  • 1
  • 4
  • 19

1 Answers1

1

I'm afraid your code does not compile. First of all, you need to declare your variables correctly. You should also use Option Explicit.

Option Explicit

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

The count and ReDim lines are OK, but you are assuming that the two selections are both the same size. Will that always be the case?

Then I'm not sure what it is you want to do, but I'm guessing you just want to save the values in user_range into points.

You need to adress them a bit different:

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
Community
  • 1
  • 1
Olle Sjögren
  • 5,315
  • 3
  • 31
  • 51
  • Sorry about that. Yes that is how i have the variables defined in the sub. Yes, i want to take the two non contgiuous ranges addressed by user_range, and copy those values into points, where the rest of the sub would then work on them. – Russ Urquhart Sep 21 '12 at 21:35
  • Good to hear! If my answer was helpful for you, you can close the question by clicking the checkmark beside the answer. – Olle Sjögren Sep 24 '12 at 07:53