array - "Type mismatch"

almagg

Well-known Member
Joined
Aug 21, 2002
Messages
705
Issues are numbered in the below code. Thanks for the help.
1) When I set both above dimensions to 'Integer' this line errrors as 'Type mismatch'

2) I get no value for 'myvalue' in the Watch window but I let a cell equal this value and it was correct.

3) program runs up to here and then I get a 'Type mismatch'

Dim myarray() As Variant
Dim myvalue As Variant

Range(Selection, Selection.End(xlDown)).Select
elements = Selection.Count
ReDim myarray(elements, 1)
For i = 1 To elements
.....myarray(i, 1) = Selection.Offset(i - 1, 0).Value ***1
Next i

For i = 1 To elements - 1
.....myvalue = myarray(i, 1) ***2
.....For j = 1 To elements - 1
..........If myvalue > myarray(j + 1, 1) Then ***3
etc...
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You change the selection to be a range, and then use offset on it, and appear to be assuming that will return a single cell ... it won't. This would do better:
Code:
Sub mission()
Dim myarray() As Integer
Dim myvalue As Integer

Set mydata = Range(Selection, Selection.End(xlDown))
elements = Selection.Count
ReDim myarray(elements, 1)
For i = 1 To elements
  myarray(i, 1) = mydata.Cells(i, 1).Value '***1
Next i

For i = 1 To elements - 1
   myvalue = myarray(i, 1) '***2
   For j = 1 To elements - 1
     If myvalue > myarray(j + 1, 1) Then '***3
        '
        End If
    Next
Next
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top