+ Reply to Thread
Results 1 to 19 of 19

Setting values from array

  1. #1
    Registered User
    Join Date
    12-08-2016
    Location
    Rotterdam, the Netherlands
    MS-Off Ver
    2016
    Posts
    24

    Setting values from array

    Good day,

    I'm want to debug.print two variables (Relation, Account) based on the values from an array.

    Relation Account
    A 1
    B 2
    C 3
    D 4
    E 5

    When a try to set the variable I receive a object-error.

    Does anyone know what I'm doing wrong?

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    01-16-2017
    Location
    [email protected]
    MS-Off Ver
    2016
    Posts
    5

    Re: Setting values from array

    Hi AlexJr-

    I believe the following line would generate an error:
    Please Login or Register  to view this content.
    because since it is after the next j line, j will actually be UBound(ReferenceDataRange, 2)+1 at that point, outside of the array bounds, which would generate an error. Unclear what you are doing with that line of code but make sure that j is within the upper bound of the array's columns when you call it...

    Hope that helps,
    TheSilkCode

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Setting values from array

    What are you trying to do?
    Do you need to debug the values of the stored items in the array?
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Setting values from array

    Try this
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-08-2016
    Location
    Rotterdam, the Netherlands
    MS-Off Ver
    2016
    Posts
    24

    Re: Setting values from array

    Thanks! That resolved it.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Setting values from array

    You're welcome. Glad i can offer some help

  7. #7
    Registered User
    Join Date
    12-08-2016
    Location
    Rotterdam, the Netherlands
    MS-Off Ver
    2016
    Posts
    24

    Re: Setting values from array

    Would you happen to know how I can best have it find (and debug.print) each cell address for each relation?

    I added the code that I was working together with your solution but now the address line is broken.

    Looking forward to your reply.

    Please Login or Register  to view this content.

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

    Re: Setting values from array

    If you leave Relation and Account as Ranges then:
    Debug.Print Relation.Value, etc.
    Then Debug.Print Relation.Address will give you the string address.
    Ben Van Johnson

  9. #9
    Registered User
    Join Date
    12-08-2016
    Location
    Rotterdam, the Netherlands
    MS-Off Ver
    2016
    Posts
    24

    Re: Setting values from array

    If I change Relation and Account as Ranges the below code breaks

    Please Login or Register  to view this content.

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

    Re: Setting values from array

    Set Relation...

  11. #11
    Registered User
    Join Date
    12-08-2016
    Location
    Rotterdam, the Netherlands
    MS-Off Ver
    2016
    Posts
    24

    Re: Setting values from array

    Do you mean as below? It is still broken.

    Please Login or Register  to view this content.

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

    Re: Setting values from array

    You must do a FIND before you can use FindNext

    No workbook so can't test:
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    12-08-2016
    Location
    Rotterdam, the Netherlands
    MS-Off Ver
    2016
    Posts
    24

    Re: Setting values from array

    That makes sense but the below code is still broken.

    How can I resolve?

    Please Login or Register  to view this content.

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

    Re: Setting values from array

    My mistake, trying to post without testing. ReferenceDataARange is not a range object but a 2D array so the .Value is wrong.
    relation.Value = referenceDataRange(i, 1)
    account.Value = referenceDataRange(i, 2)

  15. #15
    Registered User
    Join Date
    12-08-2016
    Location
    Rotterdam, the Netherlands
    MS-Off Ver
    2016
    Posts
    24

    Re: Setting values from array

    This is still not working. I'm receiving a object variable or with block variable not set runtime error 91.

    I have tried different variation by adding a with block, objects etc but at this point it is guess work for me.

    Below is my actual code.

    Do you know what is wrong?

    Please Login or Register  to view this content.

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

    Re: Setting values from array

    When you declared the variables Relation and Account as ranges with:

    Dim Relation As Range
    Dim Account As Range
    You were saying that you were going to use Relation and Account to "refer to" or "point to" ranges of cells in a worksheet.
    Once you declare your intentions (i.e., DIM), they must be made to actually point to/refer to some cells. This is done with the SET Statement.

    Dim only grabs some empty/unused available memory area and reserves (tags) it Relation or Account (in this case). You must point them to a range of cells:
    Set Relation = some cell/range of cells.
    Set Account = some other cell/range of cells

    Once you have pointed them to the cells you can then use

    With Relation
    .Value = ReferenceDataRange(i, 1)
    End With
    Account.Value = ReferenceDataRange(i, 2)


    There is no Set for Relation and Account so the With Relation translates to With NOWHERE, put the data from my array... which results in the Object or With block error.


    But!
    Notice that, in your code, you are only using Relation and Account to hold data values from an array. They never are used to refer to ranges of cells; therefore, they cannot be declared as Range variables. I don't know what kind of data you are working with (no workbook to look at ) so I'm guessing (again) that it is string or maybe integer.

    Dim Relation as ? (variant, string, long?)

    Dim Account as ...
    Relation = ReferenceDataRange(i, 1)
    Account = ReferenceDataRange(i, 2)

    I've noticed that you want to assign an account number after Relation is found by the search code, but there is no code to actually put that back in a cell in the workbook. So it looks like you still need code to put the account in some cell in the same row as that where the relation is found (???)


    Please Login or Register  to view this content.
    Last edited by protonLeah; 01-22-2017 at 05:49 PM.

  17. #17
    Registered User
    Join Date
    12-08-2016
    Location
    Rotterdam, the Netherlands
    MS-Off Ver
    2016
    Posts
    24

    Re: Setting values from array

    Thanks! Changing Relation and Account to Variant and removing .value did it.

    Indeed the last step is for the related account to be entered into the cell two columns to the left of the found address.

    I've added the following code and it works perfectly.

    Please Login or Register  to view this content.
    Thanks for your help!
    Last edited by AlexJr; 01-23-2017 at 06:01 PM.

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

    Re: Setting values from array

    You only need one line
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    12-08-2016
    Location
    Rotterdam, the Netherlands
    MS-Off Ver
    2016
    Posts
    24

    Re: Setting values from array

    Oh okay, thanks! That looks better indeed!

+ 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. array class values not setting properly
    By twozedz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-27-2016, 10:08 AM
  2. Setting/sorting an Array of Strings
    By ebase131 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-07-2013, 03:04 PM
  3. [SOLVED] Setting Array value to String which has a quote in it
    By jebrezov in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-29-2012, 03:30 PM
  4. VBA Setting Properties in an Array
    By Uziel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-29-2010, 03:03 PM
  5. Runtime Error 1004 when Setting Setting Series Values
    By tonymctigue in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 04-09-2010, 10:05 AM
  6. Setting an array
    By richardlaw in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-27-2009, 05:24 PM
  7. Setting an array range of cells???
    By Simon Lloyd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2006, 10:30 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