+ Reply to Thread
Results 1 to 5 of 5

Run Time Error for arrays

  1. #1
    Registered User
    Join Date
    04-05-2016
    Location
    Addison, Texas
    MS-Off Ver
    mac 2011
    Posts
    2

    Run Time Error for arrays

    Here is the code and I am getting compile error - Run Time Error 13 - I have made the text bold where I got the issue

    Sub r2c()

    Sheets("Sheet1").Select

    Dim a As Integer
    Dim x As Integer
    Dim n As Integer
    Dim i As Integer
    Dim w As Integer
    Dim strarray As Variant
    Dim lastcol As Long

    x = 2

    For a = 2 To 4

    Sheets("Sheet1").Select
    cust = Cells(a, 1).Value
    prod = Cells(a, 2).Value

    n = 3


    Do Until IsEmpty(Cells(a, n))

    i = 1

    strarray(i) = Cells(a, n).Value
    strarray(i + 1) = Cells(a, n + 1).Value

    n = n + 2
    i = i + 2

    Loop

    i = 1
    w = ((i - 1) / 2 - 1)

    Sheets("Sheet2").Select

    Cells(x, 1).Value = cust
    Cells(x, 2).Value = prod
    Cells(x, 3).Value = strarray(i)
    Cells(x, 4).Value = strarray(i + 1)

    For p = 1 To w


    Cells(x + p, 3).Value = strarray(i)
    Cells(x + p, 4).Value = strarray(i + 1)

    i = i + 1

    Next p


    x = x + 3

    Next a

    End Sub
    Last edited by santum4; 04-05-2016 at 05:57 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run Time Error for arrays

    strarray isn't an array.

    You either need to declare it as an array with appropriate dimensions or declare it as an array without dimensions and use ReDim Preserve to increase it's dimensions dynamically as you loop.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    04-05-2016
    Location
    Addison, Texas
    MS-Off Ver
    mac 2011
    Posts
    2

    Re: Run Time Error for arrays

    can you please tell me how to delcare the array properly , it is one dimensioanl and at max may contain 50 values

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run Time Error for arrays

    What are you trying to put in the array?

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,570

    Re: Run Time Error for arrays

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Arrays: Run-time error '424': Object required
    By Billroz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-02-2016, 08:23 PM
  2. Declaring multiple multi-dimensional arrays (jagged arrays) - compile error?
    By dfribush in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-20-2013, 05:06 PM
  3. run-time error ;2147023179 (800706b5) time automation error interface unknown
    By karthik72 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-02-2012, 09:31 AM
  4. [SOLVED] Improving my Error Handling With Arrays
    By freakytiki34 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-23-2012, 05:14 PM
  5. Sum time with criteria of 3 arrays
    By Nazerith in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-05-2011, 09:32 PM
  6. Help needed with #REF! error (arrays)
    By robotlust in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-17-2008, 08:53 PM
  7. Error with a For loop with arrays
    By baldomero in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-22-2005, 02:05 PM

Tags for this Thread

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