Home Register Members List Search Today's Posts Mark Forums Read

Go Back   TechFuels Forum > Software > Windows XP

Reply
 
LinkBack Thread Tools
Freddy Smits
Member
 

Freddy Smits is offline  
Old 07-01-2009, 07:22 AM
  #1 (permalink)
Creating an Excel macro using visual basic

One of the most tedious tasks you can be faced with in Excel is having to change the format of imported data to match the rest of the workbook.

Let's say there are hundreds of names in the format "Gates, Bill" and "Minogue, Kylie" and you'd like them to read "Bill Gates" and "Kylie Minogue". This can be done by using Excel's string functions to extract the SWllames and forenames into temporary columns, recombining them with spaces between the names and then pasting them over the original data, but this takes a lot of setting up and it's easy to make mistakes. A much better option is using a Visual Basic macro that goes through the names and con'ects them without affecting any other parts of the worksheet.

Name:  Creating an Excel macro using Visual Basic.jpg
Views: 392
Size:  44.8 KB

If you've had any experience in programming you'll recognise this as a ForlNext loop that goes through each selected cell and examines its contents looking for a comma. If it finds one, it takes the name following the comma, adds a space, and then appends the remainder of the name.

Fortunately, you don't need to know how it works in order to use it. Just set yourself up with an Excel spreadsheet and type in a few names using the pattern surname, first name. Use Tools, Macro, Macros to summon the Macros dialogue box. Type Switch as the name of the macro and click Create. The Visual Basic Editor opens with Sub and End Sub lines for the Switch macro already in place. Type the code listed above between these two lines, pressing Enter after each line. Press Alt and Q to retum to the worksheet, then save it as Names.xls with its macro in place.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual basic editor in word Fredrick Borren Windows XP 0 07-01-2009 07:16 AM
Desktop Publishing Program in Visual Basic willi CPU & Components 1 02-21-2009 07:40 AM
Creating a basic " Hello World " Program Walker Programming 0 10-27-2008 09:41 AM
Visual Basic Programming aiantin465 Programming 0 07-05-2008 09:50 AM
Macro techno23 Programming 0 03-26-2008 11:58 AM


All times are GMT +1. The time now is 01:40 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0
Copyright Techfuels -->
SEO by SubmitEdge


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151