+ Reply to Thread
Results 1 to 10 of 10

How to use a global array correctly.

  1. #1
    Registered User
    Join Date
    04-04-2011
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    31

    How to use a global array correctly.

    My code is as follows and then I will explain.

    Please Login or Register  to view this content.
    So basically I am trying to save lines of code by using For-Next loops and then working on this array. My problem appears in the second sub

    Please Login or Register  to view this content.
    It says Object required which I am assuming is because I have declared my array wrong. Can somebody confirm or deny this for me? You make something global by putting it outside the subs like the following...

    Please Login or Register  to view this content.
    Anyways any help is much appreciated. Thanks for your guys help.
    Last edited by Brad4444; 04-08-2011 at 03:01 PM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: How to use a global array correctly.

    Not sure what you are doing. You assign strings to Description but then you go through and empty it. What are you trying to achieve?

  3. #3
    Registered User
    Join Date
    04-04-2011
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: How to use a global array correctly.

    I am attempting to create a user form where the person enters in each value (on the user form) and then read that data into the last row of an excel sheet.

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: How to use a global array correctly.

    OK, I see now what you were trying to do. Can you post a workbook?

  5. #5
    Registered User
    Join Date
    04-04-2011
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: How to use a global array correctly.

    Sorry, I can't.

    EDIT:

    In the lines where the problem occurs

    Please Login or Register  to view this content.
    If I say Descriptions.Value would this call the text box value I am looking for? I guess I am asking "Am I calling the value syntactically correct?"
    Last edited by Brad4444; 04-08-2011 at 12:07 PM.

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,219

    Re: How to use a global array correctly.

    What happens if you use
    Please Login or Register  to view this content.
    ?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: How to use a global array correctly.

    Is this supposed to clear controls?

    Please Login or Register  to view this content.
    If so, it should look something like this:
    Please Login or Register  to view this content.
    or maybe this:
    Please Login or Register  to view this content.
    In the first case, you are iterating through an array of controls. In the second, through an array of control names.
    Last edited by shg; 04-08-2011 at 01:05 PM.
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Registered User
    Join Date
    04-04-2011
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: How to use a global array correctly.

    Sorry Shg, your code didn't help but it got me thinking.

    Please Login or Register  to view this content.
    What I want to do is assign a cell on a worksheet a value. I am storing strings in my array but they are just placeholders to call upon specific spots from my userform.

    So what I need to know is where does the first element of an array in VBA begin? More importantly though... the code above gives me the error "type mismatch". Why? Once again thanks for all your guys help.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: How to use a global array correctly.

    (Many) Controls have a Value property, a Range has a Value property, Variants that represent objects have a Value property if the Object it represents does.

    Variants used as ordinary variables (strings, numbers, ..., or arrays of same) do not.

    Only Objects have Properties and Methods.

    That was the point of my two examples.
    Last edited by shg; 04-08-2011 at 02:29 PM.

  10. #10
    Registered User
    Join Date
    04-04-2011
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: How to use a global array correctly.

    Point taken now. The idea is working. Weird bug though that it offsets to far.

+ 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