+ Reply to Thread
Results 1 to 10 of 10

Array List of Fonts?

Hybrid View

andrew c. Array List of Fonts? 07-27-2011, 04:33 PM
Leith Ross Re: Array List of Fonts? 07-27-2011, 04:36 PM
andrew c. Re: Array List of Fonts? 07-27-2011, 04:59 PM
Leith Ross Re: Array List of Fonts? 07-27-2011, 05:03 PM
andrew c. Re: Array List of Fonts? 07-27-2011, 05:09 PM
Leith Ross Re: Array List of Fonts? 07-27-2011, 05:10 PM
andrew c. Re: Array List of Fonts? 07-27-2011, 05:20 PM
Colin Legg Re: Array List of Fonts? 07-27-2011, 05:34 PM
andrew c. Re: Array List of Fonts? 07-27-2011, 07:41 PM
Leith Ross Re: Array List of Fonts? 07-27-2011, 08:00 PM
  1. #1
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Array List of Fonts?

    I'm trying to do an arraylist of fonts but I keep getting the error Object variable or with block variable not set. here is my code:


        Dim formatArrayRight(7 To 60) As Font
        Dim act As Integer
        For act = 7 To 60
        formatArrayRight(act) = Range("M" & act).Font
        Next
    Can you create Font arrays?
    Last edited by andrew c.; 08-04-2011 at 01:52 PM.

  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,259

    Re: Array List of Fonts?

    Hello Andrew,

    What type of an array are you trying to create? A array of font names or something else?
    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
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: Array List of Fonts?

    I would like an array that gets the font formatting, so if it were in bold or italics, or both, etc. But I don't want to make a ton of boolean arrays for bold, italics etc

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

    Re: Array List of Fonts?

    Hello Andrew,

    You can get those settings using the Font.FontStyle property which is a variant.
        Dim formatArrayRight(7 To 60) As Variant
        Dim act As Integer
        For act = 7 To 60
          formatArrayRight(act) = Range("M" & act).Font.FontStyle
        Next

  5. #5
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: Array List of Fonts?

    ohhhh Thanks a Ton!!!

    This doesn't take into account the font size. Will I need a seperate array for this?
    Last edited by andrew c.; 07-27-2011 at 05:12 PM.

  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,259

    Re: Array List of Fonts?

    Hello Andrew,

    Glad I could help.

  7. #7
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: Array List of Fonts?

    Leith Sorry I went back and edited my last post so you probably didn't see my question, but is there a data type other than fontstyle that will take into account the bold, italic, as well as the font size. Currently the size is not being adjusted from font style?

  8. #8
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Array List of Fonts?

    Hi Andrew,

    One thing you could do is create a structure called a user defined type (UDT) to hold the relevant values you need. For example:
    Type tFont
        Fontstyle As Variant
        Size As Variant
    End Type
    
    Sub foo()
    
        Dim formatArrayRight(7 To 60) As tFont
        Dim act As Long
         
        For act = 7 To 60
            With Range("M" & CStr(act)).Font
                 formatArrayRight(act).Fontstyle = .Fontstyle
                 formatArrayRight(act).Size = .Size
            End With
        Next act
    
    End Sub
    It's quite unusual to give an array a lower bound of 7 though. Usually programmers use 0 or 1.

    By the way, the reason the code errored in your original post is because Font is an object, so you need to use the Set keyword:
        '(your original code)
    
        Dim formatArrayRight(7 To 60) As Font
        Dim act As Integer
        
        For act = 7 To 60
            Set formatArrayRight(act) = Range("M" & act).Font
        Next act
    Hope that helps,

    Colin

    RAD Excel Blog

  9. #9
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: Array List of Fonts?

    Thanks Colin

    I started the array at 7 because it references static cells, so it make more intuitive sense this way.

    Where do you put the type declaration? I did it outside the sub and I got the error on declaring the array of tFont that the user defined type didn't exist.

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

    Re: Array List of Fonts?

    Hello Andrew,

    You need to place the type declaration at the top of a standard VBA module before any Sub or Function definitions.

+ 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