Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 10th, 2007, 02:42 AM
Registered User
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBA filtering help needed!

Hi all,

I am trying to create some code in order to remove characters from a phone number and convert into a string to place back into an excel database. The phone numbers have country codes attatched so only wish to remove all characters.

e.g of a phone number:
0773333333 |44|-2| @

There are over 5000 records of phone numbers so an =MID function is not possible. Any help would be greatly appreciated.

Many Thanks

 
Old April 12th, 2007, 10:59 AM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

If you have a limited set of characters to remove, I'd use Replace as follows (Assuming The # is in column B):

************************************************** *****************
dim sValue As String, iRowOn As Long
sValue = Replace(Cells(iRowOn, 2).value, "|", "")
sValue = Replace(sValue, "@", "")
'***Other characters to remove / string manipulations***
Cells(iRowOn, 2).value = sValue
************************************************** *****************


Otherwise you'll have to check character by character as such:
************************************************** *****************
dim iCharOn As Long, sValue As String, sChar as string

For iCharOn = 1 To Len(Cells(iRowOn, 2).Value)
  sChar = Mid(Cells(iRowOn, 2).Value, iCharOn, 1)
  If Val(sChar) > 0 Or sChar = "0" Then sValue = sValue & sChar
  '***Other logic processing of character can be added***
Next
Cells(iRowOn, 2).Value = sValue
************************************************** *****************

Hope one of these helps you.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Needed to write vba for Pivot Table in Excel sunny76 Excel VBA 1 June 28th, 2005 01:44 AM
Access VBA help needed...!! jonwitts Access VBA 4 May 4th, 2005 09:41 AM
Help Needed on VBA lyndon Access VBA 5 April 14th, 2005 07:49 PM
Saving Excel VBA code gives problems - Help needed mjaitly Excel VBA 0 April 14th, 2004 07:23 AM
Word VBA Syntax Needed SerranoG VB How-To 4 October 28th, 2003 02:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.