+ Reply to Thread
Results 1 to 3 of 3

Array Assign Error

Hybrid View

  1. #1
    Registered User
    Join Date
    03-02-2008
    Posts
    39

    Array Assign Error

    What is wrong with the following code? How do I fix it? I get a a run time error 13 "Type Mismatch" error when I execute.

    Option Explicit
    
    Dim S As Variant
    
    Sub Calc1()
        S(1, 1) = 2  
        S(2, 1) = 3
        S(3, 1) = 4
    End Sub
    Thanks,
    Last edited by VBA Noob; 08-14-2008 at 08:15 AM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    You have to declare the size of the array
    Dim S(1 to 3, 1 to 1)...
    though I don't think you need the second dimension.

  3. #3
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    Hi

    You need to dimension your array before you can fill it with values:

    Option Explicit
    
    Dim S As Variant
    
    Sub Calc1()
        ReDim S(1 to 3,1 to 1)
        S(1, 1) = 2  
        S(2, 1) = 3
        S(3, 1) = 4
    End Sub
    Richard

+ Reply to Thread

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