Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2009
    Location
    edmond,ok
    Posts
    4

    Unanswered: pass values from excel worksheet to VBA array

    hi guys,

    i'm a newb here as well with excel and vba, i'm trying to do my homework which requires me to pass values from an array in excel worksheet to VBA and print it in a msg box

    i've tried

    dim arr as variant
    arr = range("A1:A6").value
    msgbox arr

    but it didn't work.

    the array is number(double) and the msgbox would be combination between string and number
    ex:the numbers are 1,2,3,4,5,6

    that's the first step of the homework the second is i have 2 list of array

    year:1999 - 2002
    profit:10,20,30,40

    i have to find the max profit and get the year when it occurs

    i'd really appreciate any help/suggestions, oh and i did try the search function but couldn't get any relevant result.

    Ray

  2. #2
    Join Date
    May 2009
    Posts
    258
    Take of the .Value and you should have it.

    Ax

  3. #3
    Join Date
    Sep 2009
    Location
    edmond,ok
    Posts
    4
    Quote Originally Posted by Ax238
    Take of the .Value and you should have it.

    Ax
    i tried that and that didn't work.

    here's the code

    Sub testAr()
    Dim arr As Variant
    arr = Range("A1:A6")
    MsgBox TypeName(arr)

    End Sub

    the result is Variant()


  4. #4
    Join Date
    May 2009
    Posts
    258
    Doesn't seem to be a problem with it. What are you expecting it to return?

    Edit: I just noticed you said this is homework. Homework is not our work, it's yours. Let me teach you the first and most important thing you can know if you want to succeed in your educational endeavors:
    Let me google that for you
    Last edited by Ax238; 09-18-09 at 17:19.

  5. #5
    Join Date
    Sep 2009
    Location
    edmond,ok
    Posts
    4
    o well, i'm just trying to learn. but thanks anyway. i know it's not your work but a help would be appreciated

  6. #6
    Join Date
    May 2009
    Posts
    258
    I have helped you, but there's a sense of satisfaction figuring things out on your own and I don't want to rob you of that. The link I gave you should lead you directly to the correct answer.

    Have fun!

    Ax

Posting Permissions

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