LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gord Dibben
 
Posts: n/a
Default Formula to replace invalid filename characters

Public Sub StripAll_But_NumText()
Dim rConsts As Range
Dim rcell As Range
Dim i As Long
Dim sChar As String
Dim sTemp As String

On Error Resume Next
Set rConsts = Selection.SpecialCells(xlCellTypeConstants)
On Error GoTo 0
If Not rConsts Is Nothing Then
For Each rcell In rConsts
With rcell
For i = 1 To Len(.text)
sChar = Mid(.text, i, 1)
If sChar Like "[0-9a-zA-Z]" Then _
sTemp = sTemp & sChar
Next i
.Value = sTemp
End With
sTemp = ""
Next rcell
End If
End Sub


Gord Dibben MS Excel MVP

On Fri, 27 Jan 2006 09:50:42 -0600, tschultz
wrote:


I have a form being exported into Excel from an application where the
customer names may include any one or more of the following characters:
\ / : * ? < |. I do not have the option of guaranteeing these
characters are not used since the customer data source is SAP. Since
these characters can not be used as part of a file name I'm struggling
with some code I have set up to perform a Save As at the end of a
formatting macro.

Say the customer name in cell A1 contains one or more invalid
characters, how do I remove or replace them with something else? I
currently have the formula in the macro replacing a / with a space, but
after further checking some of the customer names have two quotation
marks or the symbol.

Route"66" = Route 66
ISRunners Inc = IS Runners Inc

Ideally I would like the formula to check for any one or more of the
invalid characters and remove or replace them with something else to
make the new value a valid part of a file name. In a previous form,
not using macros, I performed each replacement of characters in a
separate cell and took the final cell as part of the filename, but I'd
like to perform this in one cell and record the formula for placement
into my macro.

I've tried several different ways with no luck and maybe there are
Excel limitations I am not aware of. I'm experienced with formula's,
but this one has me stumped and maybe it's not even possible.

Any replies would be greatly appreciated. I'm hoping someday I can
provide help to other users as this forum has answered many questions
I've searched for.

tschultz


 
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
Formula Problem - interrupted by #VALUE! in other cells!? Ted Excel Worksheet Functions 17 November 25th 05 05:18 PM
use replace to edit a formula with wildcards koskyil Excel Worksheet Functions 11 August 23rd 05 06:13 PM
Formula checking multiple worksheets sonic-the-mouse Excel Worksheet Functions 2 June 5th 05 03:28 AM
if cell starts with characters formula Norman Kong via OfficeKB.com Excel Discussion (Misc queries) 3 March 24th 05 10:18 AM
Problem with VBA returning the contents of a long formula. [email protected] Excel Discussion (Misc queries) 2 February 23rd 05 12:14 AM


All times are GMT +1. The time now is 04:02 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"