+ Reply to Thread
Results 1 to 10 of 10

Create a GUID in entire column

  1. #1
    Registered User
    Join Date
    10-13-2009
    Location
    Cleveland, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    4

    Create a GUID in entire column

    Hi Folks,

    I've done a lot of programming and scripting, but none in Excel. I have a little experience with the VBA interface as well.

    I have a spreadsheet that I use to populate a MySql database. It has a hierarchical relationship in the spreadsheet which is accomplished through a column called GUID and another column called Parent GUID. I've been using a website to generate GUIDs for me and pasting them into the first column one at a time, then copying to the second column where necessary. It takes forever.

    So, I'm wondering if I can write (or better - paste!) a function that will automatically generate the first column of GUIDs. I've googled and found several functions that create a guid, but I don't really understand how to call the function from excel. Also, I don't want to manually call it thousands of times. I'd just like to call it once and have it generate GUIDs for the entire column.

    I'll still copy and paste to fill in the Parent GUID column.

    Thanks in advance for any help.

  2. #2
    Registered User
    Join Date
    10-13-2009
    Location
    Cleveland, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Create a GUID in entire column

    okay... well i hate waiting so I started to solve this myself

    here's what i put in the vba code window:
    Please Login or Register  to view this content.
    Im not sure I trust that GUID function to be unique though, which is a huge problem.
    Last edited by Leith Ross; 10-13-2009 at 12:12 PM. Reason: Added Code Tags

  3. #3
    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: Create a GUID in entire column

    Hello tvainisi,

    Here is how to correctly generate the GUID (Globally Unique Identifier) or CLSID (Class ID). Place this code in its own module in your VBA project.
    Please Login or Register  to view this content.
    Because this is a UDF (User Defined Function) you can place it in cell to return a new GUID to the cell.
    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!)

  4. #4
    Registered User
    Join Date
    10-13-2009
    Location
    Cleveland, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Create a GUID in entire column

    Thanks for the assistance Leith.

    Is there a way to not have the curly brackets around the GUID, or do I just need to use some string functions to remove them?
    Last edited by tvainisi; 10-13-2009 at 02:19 PM.

  5. #5
    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: Create a GUID in entire column

    Hello tvainisi,

    The GUID includes the curly braces. So use a Mid function to remove them. Change the last line in the macro to this...
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 10-13-2009 at 02:53 PM. Reason: Corrected spelling

  6. #6
    Registered User
    Join Date
    10-13-2009
    Location
    Cleveland, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Create a GUID in entire column

    Terrific! Thanks a bunch!

  7. #7
    Registered User
    Join Date
    10-20-2010
    Location
    Seattle
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Create a GUID in entire column

    This was a timely solution for me as well.

    One more thing. Can the hyphens also be removed from the string by a function?

    You help is appreciated.

  8. #8
    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: Create a GUID in entire column

    Hello Dirtnap,

    This thread is over a year old. You should have started a new thread and added a link back to this one. Please do so in the future. Here is the modified macro to return the GUID without the braces and hyphens.

    As a new member, please take the time to read over the Click Here for the Forum Rules .

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-20-2010
    Location
    Seattle
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Create a GUID in entire column

    My apologies - the 2009 reference didn't even register. I will read the rules.

    And thanks for the suggested function.
    Last edited by Dirtnap; 10-21-2010 at 09:32 AM.

  10. #10
    Registered User
    Join Date
    09-21-2012
    Location
    Tallahassee, FL
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Create a GUID in entire column

    I am getting an error on Windows 7 on (Compile Error: Type Mismatch on VarPtr) - I am using Option Explicit. the Definition says it is hidden:

    Please Login or Register  to view this content.
    thanks for the help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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