+ Reply to Thread
Results 1 to 10 of 10

Iterate over Type

Hybrid View

jakopak Iterate over Type 03-01-2017, 12:14 PM
xlnitwit Re: Iterate over Type 03-01-2017, 12:31 PM
jakopak Re: Iterate over Type 03-01-2017, 12:43 PM
xlnitwit Re: Iterate over Type 03-01-2017, 12:47 PM
jakopak Re: Iterate over Type 03-01-2017, 12:50 PM
Norie Re: Iterate over Type 03-01-2017, 12:54 PM
jakopak Re: Iterate over Type 03-01-2017, 01:12 PM
xlnitwit Re: Iterate over Type 03-01-2017, 12:57 PM
Norie Re: Iterate over Type 03-01-2017, 01:29 PM
jakopak Re: Iterate over Type 03-01-2017, 01:35 PM
  1. #1
    Forum Contributor
    Join Date
    02-05-2015
    Location
    czech
    MS-Off Ver
    2010
    Posts
    172

    Iterate over Type

    Hello Dear Excel Forum

    Is it possible to iterate over Type?
    I have following method of looping doesn't work:

    Public imtype As mtype
    Public Type mtype()
    Item1 As Long
    Item2 As Long
    Item3 AS Long
    End Type
    
    
    Sub howtoiter()
    Dim el As Variant
    With imtype
    Item1 =1
    Item2 =2
    Item3 =3
    End With
    
    For each el in imtype
       do something with el
    Next el
    
    End Sub
    Here is a method for iterating over Enum.
    https://msdn.microsoft.com/en-us/library/58hssdz9.aspx
    Last edited by jakopak; 03-01-2017 at 12:19 PM.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Iterate over Type

    Hi,

    The Enum method is VB rather than VBA. There is no way to iterate over a type in VBA. Where would it be useful?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    02-05-2015
    Location
    czech
    MS-Off Ver
    2010
    Posts
    172

    Re: Iterate over Type

    Hi xlnitwit,
    In public Type I have defined items. The items are conditional formulas expressed as string. I would like to do some conversion/operation on those items when condition is met. I can use array but then I would have to reference items like formulas(1) insted of formulas.item1. I would have to remember what formulas(1) is or look it up whenever I need it.
    Last edited by jakopak; 03-01-2017 at 12:47 PM.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Iterate over Type

    I'm still not really clear as to how iterating over them would help, but I think you would probably require a simple class rather than a UDT, which are a little limited in scope.

  5. #5
    Forum Contributor
    Join Date
    02-05-2015
    Location
    czech
    MS-Off Ver
    2010
    Posts
    172

    Re: Iterate over Type

    Well, whenever condition is met I would iterate over Type items and replace for example string "Row" with "Column" or something like that.
    formulas.Item1=Replace(formulas.Item1,"ROW","COLUMN")
    Last edited by jakopak; 03-01-2017 at 12:53 PM.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Iterate over Type

    Is formulas(1) much different to formulas.item1?
    If posting code please use code tags, see here.

  7. #7
    Forum Contributor
    Join Date
    02-05-2015
    Location
    czech
    MS-Off Ver
    2010
    Posts
    172

    Re: Iterate over Type

    Quote Originally Posted by Norie View Post
    Is formulas(1) much different to formulas.item1?
    Yes, because item1 can be named for example melons. With formulas(1) I have to remember formulas(1) means melons. I would have to resize array each time I add an item.
    Maybe I can patch up something like that in Class with Array and Type, but it will be helluva of code.

    Quote Originally Posted by xlnitwit View Post
    I'd suggest you should probably be using a Collection or a Dictionary rather than a UDT.
    Collection will do, thanks. Though I will have no intelisense. Still iterating over type would be handy.
    Last edited by jakopak; 03-01-2017 at 01:27 PM.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Iterate over Type

    I'd suggest you should probably be using a Collection or a Dictionary rather than a UDT.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Iterate over Type

    If you need to do any sort of 'resize' then using an array or collection is probably the right way to go because I don't think you can resize a UDT.

  10. #10
    Forum Contributor
    Join Date
    02-05-2015
    Location
    czech
    MS-Off Ver
    2010
    Posts
    172

    Re: Iterate over Type

    Yes, collection is right tool to use here, though not convenient to use as Type.

+ 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. iterate
    By Gaurav_92 in forum Excel General
    Replies: 1
    Last Post: 06-03-2014, 01:42 AM
  2. [SOLVED] Iterate Through Names, list unused: Type Mismatch with Cells.Find
    By tlafferty in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2012, 04:03 PM
  3. Using For Each to iterate each cell in a row
    By 6StringJazzer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-02-2011, 12:19 PM
  4. need to iterate, or something...
    By jacquesmckenna in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-28-2008, 11:34 AM
  5. Iterate through a form
    By RobEdgeler in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-17-2005, 01:58 PM
  6. [SOLVED] Iterate through controls
    By lgbjr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-28-2005, 10:05 AM
  7. Can't iterate thru a row with For
    By peter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2005, 01:06 AM

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