Delete unwanted characters

Grzegorz1997

New Member
Joined
Aug 30, 2018
Messages
1
I have a little issue with unwanted characters at the end of number. I mean "numerek". There is no blank space, because function Replace work and it is no help. I tried use function Trim, but still no help for me. For example "numerek" = "1121123RE3" and it is 13 characters for VBA, but there is no space and exactly we can see that there is 10 characters! When I use MsgBox (numerek) it gives "1121123RE3 " . How can I delete this " " characters, when I know that it is no blank space? This program has to give me all number without "blank space" but it is not blank space. I'm using it in Outlook VBA. Please help :)

Rich (BB code):
Rich (BB code):
Rich (BB code):
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Dim MyOlNamespace As NameSpace
Dim MySelectedItem As MailItem
Dim Response As String
Dim fso As Object, TmpFolder As Object
Dim tmpFileName As String
Dim wrdApp As Object
Dim wrdDoc As Object
Dim bStarted As Boolean
Dim dlgSaveAs As FileDialog
Dim fdfs As FileDialogFilters
Dim fdf As FileDialogFilter
Dim i As Integer
Dim WshShell As Object
Dim SpecialPath As String
Dim msgFileName As String
Dim strCurrentFile As String
Dim strName As String
Dim oRegEx As Object
Dim intPos As Long
Dim itm As Outlook.MailItem
Dim currentExplorer As Explorer
Dim Selection As Selection

Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim oldName

Dim file As String
Dim DateFormat As String
Dim newName As String
Dim numerek As String
Dim tytul_maila

Dim enviro As String

'Set currentExplorer = Application.ActiveExplorer
'Set Selection = currentExplorer.Selection

Set MyOlNamespace = Application.GetNamespace("MAPI")
Set MySelectedItem = ActiveExplorer.Selection.Item(1)
Set fso = CreateObject("Scripting.FileSystemObject")

serwer = "C:\Users\GZ76576\Documents\"

If InStr(MySelectedItem.Body, "faktury/rachunku") > 0 Then
wiersz = InStr(MySelectedItem.Body, "faktury/rachunku")
wiersz_koniec = InStr(MySelectedItem.Body, "Data wpływu")
    If wiersz_koniec > wiersz Then

numerek = Mid(MySelectedItem.Body, wiersz + 20, wiersz_koniec - wiersz - 24)
numerek = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(numerek, ":", ""), "/", ""), "-", ""), "*", ""), "\", ""), " ", ""), " ", ""), "    ", ""), "|", ""), " ", ""), "_", "")


End If
End If

nrfaktury = InputBox("Wpisz numer" & vbNewLine & vbNewLine & "Zachowaj format" & vbNewLine & vbNewLine & "PRZYKLAD", , numerek)

If nrfaktury = "" Then
Exit Sub
End If
...</code>
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
try...
placing this function in a standard module
Code:
Function AlphaNumeric(TextString As String) As String
    Dim i As Integer, r As String
    For i = 1 To Len(TextString)
        Select Case Asc(Mid(TextString, i, 1))
            Case 48 To 57, 65 To 90, 97 To 122
                r = r & Mid(TextString, i, 1)
        End Select
    Next
    AlphaNumeric = r
End Function

and replacing this line in your code
Code:
numerek = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(numerek, ...etc
with
Code:
numerek = AlphaNumeric(numerek)
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top