+ Reply to Thread
Results 1 to 7 of 7

Using VBA to Parse Variables from 1 to 3 columns

  1. #1
    Registered User
    Join Date
    03-01-2010
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2003
    Posts
    12

    Using VBA to Parse Variables from 1 to 3 columns

    Hello,

    This is my first time using VBA in Excel and I'm a little confused where to start.

    Here's what I'm trying to do: In my worksheet, there's a column of data that contains "city, state. Synagogue_name". I'm trying to parse out these three values into separate fields using INSTR and MID. So far, I'm just working on INSTR.

    I think I've figured out the VBA code to find the first comma:
    Please Login or Register  to view this content.

    G1 is where I want the value to go, F1 is where the "city, state. Synagogue" data is.

    It's at this point that I get lost. I've written this as a module, but how to I activate it? I can't seem to make a macro to point to this VBA script. How would I automate this for the other records (almost 30,000 of them) in this table?

    After I figure this out, I plan on using MID to create variables out of the word between the values returned by INSTR, and them somehow get the variable into a new field.

    I've only done a bit of VBA in Access before, and that was mostly on events, so this is new stuff for me. Any help is much appreciated!

    Thanks!

    Nathan
    Last edited by ntallman; 03-02-2010 at 09:59 AM. Reason: Editing to Moderator's Request

  2. #2
    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: First time using VBA in Excel

    Welcome to the forum.

    Please take a few minutes to read the forum rules, and then edit your post to amend the thread title and add code tags to your code.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    Re: First time using VBA in Excel

    Hi
    Paste these codes in the macro window ( Alt F11) and run the macro
    Please Login or Register  to view this content.
    It splits the strings in col F into left, Middle and right and puts them in col G,H & I
    You can experiment with it by changing one parameter at a time and observing how it affects the results.
    Ravi

  4. #4
    Registered User
    Join Date
    03-01-2010
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: First time using VBA in Excel

    Thank so so much Ravi, you're a genius! I had to change a comma to a period, but this does exactly what I was working towards. Cheers!

  5. #5
    Registered User
    Join Date
    03-01-2010
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Using VBA to Parse Variables from 1 to 3 columns

    Ravi, your solution is great, but transfers the spaces from the original column to the new ones so that there is an extraneous space in new second and third columns. Any ideas how to get rid of this?

    Thanks again!

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Using VBA to Parse Variables from 1 to 3 columns

    Thanks for amending your thread title.

    Maybe this:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  7. #7
    Registered User
    Join Date
    03-01-2010
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Using VBA to Parse Variables from 1 to 3 columns

    Perfect, it works! Thanks so much!

+ 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