Results 1 to 4 of 4

Type Mismatch and Subscript out of Range for Static Array

Threaded View

  1. #1
    Registered User
    Join Date
    12-26-2011
    Location
    San Francisco
    MS-Off Ver
    Excel 2010
    Posts
    45

    Type Mismatch and Subscript out of Range for Static Array

    I get 2 different types of errors depending on how I Dim my array. I selected 4 cells when I ran the code below and it throws the error, "subscript out of range" on "MyArray(i, 1) = 1", when i = 1.

    Dim MyArray() As Variant
    ReDim MyArray(1 To Selection.Cells.Count, 1 To 3) As Variant
    Dim i As Integer
    
    For Each c In Selection.Cells
       i = i + 1
       MyArray(i, 1) = 1
       MyArray(i, 2) = 2
       MyArray(i, 3) = "awesome"
    Next c
    Then when I ran the code by changing the () from the first line, I get Type Mismatch on the MyArray(i,1) line:
    Dim MyArray As Variant
    Help! I'm new to arrays and have read through a few tutorials but this is my first time trying one.
    Last edited by BeefNoodleSoup; 03-18-2012 at 06:37 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1