+ Reply to Thread
Results 1 to 6 of 6

VBA Setting Properties in an Array

  1. #1
    Registered User
    Join Date
    11-09-2007
    Posts
    42

    Question VBA Setting Properties in an Array

    I have a range that my code loops through and sets certain words to bold. I thought it might be quicker if I created an array, did the loop in memory, then set my range equal to the array. However, it seems I cannot set the bold property in an array.

    Is it not possible? Also, is there a need to Dim the array when I can just Redim it?

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Setting Properties in an Array

    Hello Uziel,

    Your array is actual a Variant that holds a Parameter Array. To declare an Array using the Dim statement, the variable must be followed by parentheses .
    Please Login or Register  to view this content.


    The reason your array isn't changing the font is the array is loaded with the cell values. The Font Property must be used an object. In this case the object would be the cell which is a Range object. You can change the Font of a contiguous range quite easily, like this...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    11-09-2007
    Posts
    42

    Re: VBA Setting Properties in an Array

    Thank you Leith.

    I was afraid you would say that. It is a shame because it would be so much quicker in an array!

    I understand how to declare an array, I just dont understand the point. I can NOT use the dim statement and just use Redim to create it once I have the dimensions.

    Please Login or Register  to view this content.

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

    Re: VBA Setting Properties in an Array

    I can NOT use the dim statement and just use Redim
    Why not? From Help,

    Caution The ReDim statement acts as a declarative statement if the variable it declares doesn't exist at module level or procedure level. If another variable with the same name is created later, even in a wider scope, ReDim will refer to the later variable and won't necessarily cause a compilation error, even if Option Explicit is in effect. To avoid such conflicts, ReDim should not be used as a declarative statement, but simply for redimensioning arrays.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    11-09-2007
    Posts
    42

    Re: VBA Setting Properties in an Array

    OK. Just for the record I do read the help files and search Google before posting!

    Sorry

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Setting Properties in an Array

    Hello Uziel,

    What you have done is legal and you created an array. The point is really one of semantics. Your array has been created using the Array keyword and stored inside a Variant variable. The Dim statement creates a variable that is an array, either static or fixed.

+ 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