VBA example - Excel 2007: VBA code to split full names


VBA code to split full names

In this example, We use VBA built-in functions Split () and Trim() to create a simple program to split the full names in to first and last names. We use the Trim() method to remove space from the full names if any and then split the names using the Split() method.

To run this example VBA code, you will need a Form, and a CommandButton. You may type the full names in to your current worksheet.



VBA for Excel: VBA code to split the full names to first and last name


VBA code for this example:

Dim i As Integer
Private Sub CommandButton1_Click()    
   
While Cells(i, 1) <> ""
       
         splitName (Trim(Cells(i, 1))) 'remove space if any then split it
       
 
        i = i + 1
   
   
Wend

End Sub
   
Sub splitName(SName As String)    
   
Dim Names() As String
   
   
Names = Split(SName, " ") 'split the full name
   
   
Cells(i, 2) = Names(0) ' first name
   
   
Cells(i, 3) = Names(1) ' last name

End Sub  

Private Sub UserForm_Initialize()    
     i = 1 'initialize variable i to get start

End Sub

Comments

seo plugin comment

 seo plugin

Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword....wait there's even more Now what if i told you there was a simple Wordpress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at. <a href="http://www.SeoOptimizedRankings.com">Seo Plugin</a>
seo plugin http://www.SeoOptimizedRankings.com/


2015-12-30




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.