+ Reply to Thread
Results 1 to 5 of 5

Help with Type. End Type element selection

  1. #1
    Registered User
    Join Date
    08-31-2014
    Location
    Brisbane, Queensland
    MS-Off Ver
    2007
    Posts
    4

    Help with Type. End Type element selection

    Hello Everybody,

    Newbie Excel vba user (and poster).
    I actually have three simple questions, please
    The first is as per the title. I have used this construct because I have mixed data types (dates, strings, singles etc) and I believe they do not fit an array. So how do you select an element from this construct? Or does it have an auto index or similar?
    Second question: How do you call an excel formula with vba? Eg Linest(y's, x's) is it:
    some variable = xlLinest(range, range)?

    Third question: Ranges?
    If I have Dates and Sales as two elements of my Type construct (above q1) and I want to linear regress Sales against dates (above q2) how do I set up the ranges (y's and x's)

    I thank all assisters in advance. My attempts at getting this info from help files and google queries was not much help. So in desperation I turn to the electronic manual and experience
    Regards
    Murray

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,282

    Re: Help with Type. End Type element selection

    Interesting for a VBA newcomer to go straight to using Types! (You can simply use an array of Variant type which can hold anything).

    1. Like this for example:
    Please Login or Register  to view this content.
    2. It's
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    The former raises a run-time error if something goes wrong with the function, whereas the latter returns an actual error value that you can assign to a Variant variable and then test with IsError.

    3. Not really sure I follow this part. Can you elaborate?
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    08-31-2014
    Location
    Brisbane, Queensland
    MS-Off Ver
    2007
    Posts
    4

    Re: Help with Type. End Type element selection

    Thank you Rory.
    I think I had the first bit, so Q1 rephrased is (say) having populated array "y." with data records, how do I the select an (record) element from it eg the fifth record? Or is it as simple as "y."(5)? See below
    Q2: Solved - thank you
    Q3: say my array has 12 records (eg months of data - see below for an example) and I want to smooth the data, do I dump the array element out (ie unpack just the sales info eg y.mySingle) or do I access the data with Range (y.mySingle(Range?(what):Range?(what)

    R#1: y.myDate ="Jan 10", y.mySingle = 123, y.myString = "Southern", ...
    R#2: y.myDate ="Jan 11", y.mySingle = 456, y.myString = "Southern", ...
    R#3: y.myDate ="Jan 12", y.mySingle = 789, y.myString = "Southern", ...
    R#4: y.myDate ="Jan 13", y.mySingle = 212, y.myString = "Southern", ...

    I hope this is not too dumb! I do not have Excel data loaded yet because I wanted to build my solution first so I know how to import the data (format) into excel then manipulate it with vba.
    I want to learn vba so thats why I am attempting this - perhaps novice rather than newbie.
    Thank you Rory

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,282

    Re: Help with Type. End Type element selection

    If you have an array of the type, you refer to an element using y(5) and to a member of the type using say y(5).myDate

    For 3, you would be better off using separate arrays that you can pass to the function you want, unless you want to populate either more arrays from your array of UDTs, or populate ranges.

  5. #5
    Registered User
    Join Date
    08-31-2014
    Location
    Brisbane, Queensland
    MS-Off Ver
    2007
    Posts
    4

    Re: Help with Type. End Type element selection

    Ok! Rory. Thank you. I will play with these concepts to improve my understanding. I appreciate your time and effort.
    I will get back to you with either more questions or my result.
    +1

+ 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. Use a Variable to Retun an Element from a Type Array
    By tom.hogan in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-22-2014, 04:50 AM
  2. Taking an element in array (variant type) in Excel VBA
    By blackarrow in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-16-2013, 01:45 PM
  3. Error passing element of string array get ByRef argument type mismatch
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-17-2011, 02:59 PM
  4. [SOLVED] how to redim the type of variant element
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-25-2005, 03:05 PM
  5. Object Type of a selection... counting rows in a selection
    By Acid-Sky in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2005, 05:05 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