Question : Excel export Replace characters

Hi

Look at the attached Code.
It exports some data from the excel ark.

I have two type of fields, where there are som wrong charecters in the export, and I would like it to convert the characters, or delete it.
It exports "," as ",", but I would like it to convert it to "."
It Exports date like this 02-25-2010, but I would like it to delete all the "-"

Any help ?? :-)
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:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
Option Explicit
 
Sub ExportDateloenTilMultiLoen()
    Dim AppName As String
     
    ExportRow 2, -999
    ExportRowFra 2, -999
    'ExportRow -999, -999
    MsgBox "Færdig"
End Sub
 
Sub ExportRow(rStart As Long, rEnd As Long)
    'assumes export from active sheet'
    Dim ws As Worksheet, sTmp As String, sComma As String, sX As String
    Dim colOutput As Collection, lRow As Long, iCol, colFail As String, colFail01 As String, colFail02 As String
    Dim intNum As Integer
     
    Dim sFileCSV As String, lfn As Long
     
    Set colOutput = New Collection  'hold list of columns to output
    colOutput.Add Item:="A"   'after:=0
    colOutput.Add Item:="B"   'after:=0
    colOutput.Add Item:="C"   'after:=0
    colOutput.Add Item:="D"   'after:=0
    colOutput.Add Item:="E"   'after:=0
    colOutput.Add Item:="F"   'after:=0
    colOutput.Add Item:="G"   'after:=0
    colOutput.Add Item:="H"   'after:=0
    colOutput.Add Item:="I"   'after:=0
    colOutput.Add Item:="J"   'after:=0
    colOutput.Add Item:="K"   'after:=0
    colFail = "D"
    colFail01 = "I"
    colFail02 = "G"
    
    'sFileCSV = "P:\danwin\export\MLAlm.csv"
    sFileCSV = "Z:\$Kunder\FrontZ\Løn ark\MLAlm.csv"
     
    'as dont want quotes, need to use print# and build the string'
    sComma = ";"  'surround with spaces ?'
     
    Set ws = ActiveSheet
    'test for special input'
    If rEnd = -999 Then
        rEnd = ws.UsedRange.Rows.Count + ws.UsedRange.Row - 1
    End If
    If rStart = -999 Then
        rStart = ws.UsedRange.Row
    End If
     
    sTmp = ""
     
    lfn = FreeFile
    Open sFileCSV For Output As lfn
     
        For lRow = rStart To rEnd
            For iCol = 1 To colOutput.Count
                sX = colOutput.Item(iCol) & Format(lRow, "#0")
                If ws.Range(sX).Value = "0" And colOutput.Item(iCol) = colFail Then
                    'row failure'
                    sTmp = ""
                    Exit For
                End If
                If ws.Range(sX).Value = "0" And colOutput.Item(iCol) = colFail01 Then
                    'row failure'
                    sTmp = ""
                    Exit For
                End If
                
                If colOutput.Item(iCol) = colFail02 Then
                    If CInt(ws.Range(sX).Value) <= 99 Then
                        'row failure'
                        sTmp = ""
                        Exit For
                    End If
                End If
                
                If iCol = 1 Then
                    sTmp = ws.Range(sX)
                 Else
                    sTmp = sTmp & sComma & ws.Range(sX)
                End If
            Next iCol
             
            If sTmp <> "" Then
                    Print #lfn, sTmp
            End If
        Next lRow
    Close lfn
End Sub

'''''''

Sub ExportRowFra(rStart As Long, rEnd As Long)
    'assumes export from active sheet'
    Dim ws As Worksheet, sTmp As String, sComma As String, sX As String
    Dim colOutput As Collection, lRow As Long, iCol, colFail As String, colFail01 As String, colFail02 As String
    Dim intNum As Integer
     
    Dim sFileCSV As String, lfn As Long
     
    Set colOutput = New Collection  'hold list of columns to output
    colOutput.Add Item:="A"   'after:=0
    colOutput.Add Item:="B"   'after:=0
    colOutput.Add Item:="L"   'after:=0
    colOutput.Add Item:="D"   'after:=0
    colOutput.Add Item:="E"   'after:=0
    colOutput.Add Item:="F"   'after:=0
    colOutput.Add Item:="G"   'after:=0
    colOutput.Add Item:="H"   'after:=0
    colOutput.Add Item:="I"   'after:=0
    colOutput.Add Item:="J"   'after:=0
    colOutput.Add Item:="K"   'after:=0
    colFail = "D"
    colFail01 = "I"
    colFail02 = "G"
    
    'sFileCSV = "P:\danwin\export\MLFraVaer.csv"
    sFileCSV = "Z:\$Kunder\FrontZ\Løn ark\MLFraVaer.csv"
    'as dont want quotes, need to use print# and build the string'
    sComma = ";"  'surround with spaces ?'
     
    Set ws = ActiveSheet
    'test for special input'
    If rEnd = -999 Then
        rEnd = ws.UsedRange.Rows.Count + ws.UsedRange.Row - 1
    End If
    If rStart = -999 Then
        rStart = ws.UsedRange.Row
    End If
     
    sTmp = ""
     
    lfn = FreeFile
    Open sFileCSV For Output As lfn
     
        For lRow = rStart To rEnd
            For iCol = 1 To colOutput.Count
                sX = colOutput.Item(iCol) & Format(lRow, "#0")
                If ws.Range(sX).Value = "0" And colOutput.Item(iCol) = colFail Then
                    'row failure'
                    sTmp = ""
                    Exit For
                End If
                If ws.Range(sX).Value = "0" And colOutput.Item(iCol) = colFail01 Then
                    'row failure'
                    sTmp = ""
                    Exit For
                End If
                
                If colOutput.Item(iCol) = colFail02 Then
                    If CInt(ws.Range(sX).Value) >= 99 And ws.Range(sX).Value <> "0" Then
                        'row failure'
                        sTmp = ""
                        Exit For
                    End If
                End If
                
                If iCol = 1 Then
                    sTmp = ws.Range(sX)
                 Else
                    If colOutput.Item(iCol) = "E" Then
                        sTmp = sTmp & sComma & ws.Range(sX)
                    Else
                        sTmp = sTmp & sComma & ws.Range(sX)
                    End If
                End If
            Next iCol
             
            If sTmp <> "" Then
                    Print #lfn, sTmp
            End If
        Next lRow
    Close lfn
End Sub

Answer : Excel export Replace characters

Or in one statement

ws.Range(sX) = Replace(Replace(ws.Range(sX),",","."),"-","")
Random Solutions  
 
programming4us programming4us