Results 1 to 2 of 2

Thread: [Excel VBA] Getting values for VBA array from spreadsheet range

  1. #1

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    42

    [Excel VBA] Getting values for VBA array from spreadsheet range

    Hi, I have some code I am looking at, and it currently assigns values to a VBA array as a block from a range in the spreadsheet by doing:

    Code:
    Dim DataArray As Variant
    Workbooks("whatever.xlsm").Activate
    Sheets("Sheet1").Select
    DataArray = Range("A2:EV1000").Value
    I want to do this same thing without selecting. I tried

    Code:
    DataArray = Workbooks("whatever.xlsm").Sheets("Sheet1").Range("A2:EV1000").Value
    but that gave an error. What should I do? Thanks for any help!

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
    UPDATE: Apparently, the code above does work. But, the code I actually used was Windows("whatever.xlsm")... I had never seen Windows used before but it was in code I was updating a bit. So, my new question is:

    What's the different between Windows and Workbooks? Are they mostly the same? Why does Windows not work above, but Workbooks does?

    Thanks
    Last edited by ActSciMan; Jul 12th, 2011 at 03:01 PM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Excel VBA] Getting values for VBA array from spreadsheet range

    a workbook can be opened in multiple windows, using split or new window, some or all of which may not be visible
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width