LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Terry Pinnell
 
Posts: n/a
Default Macro to remove text

Dave Peterson wrote:

The easy part first.

"Option Explicit" tells excel that you're going to declare each variable you use
with a Dim statement.

Adding this to the top of your module can cause "problems" when all the
variables are not declared--but not having this can cause more and more
difficult to find problems.

For instance, with this kind of code:

Option Explicit
Sub testme()
Dim Rowl As Long
Rowl = 0
For Rowl = 1 To 10
MsgBox Row1
Next Rowl
End Sub

You won't even be able to run it. (one of those row-ell's is row-one--difficult
to catch with the naked eye.)

But with option explicit, the VBA editor will even yell at you what line is
incorrect.

If you drop the Option explict, then the VBA editor won't care if you didn't
declare all your variables (since you didn't tell it to care).

The code would run--but it would show an empty message box--Row1 (with one, not
ell) is implicitly a variant (dim xxx as Variant)--and it's never been set to
anything--so you see an empty string.

Adding "Option Explicit" may seem like it makes more work for you, but it really
stops you from spending hours looking for that #^!#@%ing typo.

And you can tell the VBE to add this line to all new modules:
Inside the VBE:
Tools|options|Editor tab
check "require variable declaration"

===========
To add the procedure to your workbook....

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel and save this workbook (so you don't have to do this
portion again). (And change the name to something more meaningful than Testme.)

Then test it out via:

tools|macro|macros...
select the macro and click run.


Many thanks, appreciate your taking the trouble to spell that out -
very helpful.

--
Terry, West Sussex, UK
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro that finds text and keeps only part of it john mcmichael Excel Discussion (Misc queries) 5 October 18th 05 10:58 PM
In Excel need macro to tell if Text Box is Blank or has Text Jerry Dyben Excel Discussion (Misc queries) 1 September 28th 05 04:07 AM
Macro or Formula to remove Text from Cells smck Excel Worksheet Functions 6 May 11th 05 03:22 AM
Remove Numbers from text David Excel Worksheet Functions 6 May 2nd 05 12:44 AM
remove spaces in text in excel GnarlyCar Excel Discussion (Misc queries) 3 February 1st 05 05:02 PM


All times are GMT +1. The time now is 09:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"