how to delete the unwanted characters like !,`,-,. etc. from my excel rows and obtain a clean sheet?here i have attached my test excel
exceldt.xlsx (9.4 KB)
Hi @ydash999,
-
Read Excel with the readragen activity.
-
Convert the datatable to a string with outdatatable.
-
Clean up the entire result string with regex.
-
You can convert it back to arraylist and turn it into a datatable.
Regards,
MY
-
put below code in text file e.g. vba.txt
-
in excel application scope call the vba function
Function removeSpecial()
Dim r As Range
Set r = ActiveSheet.UsedRange
Dim cellRange As Range
For Each cellRange In r
Debug.Print "r"
cellRange.Value = FindReplaceRegex(cellRange, "([\" & Chr(34) & "<>\(\):\!\`\-\.])", "")
Next cellRange
ActiveWorkbook.Save
End Function
Function FindReplaceRegex(rng As Range, reg_exp As String, replace As String)
'Dim regex As Object
Set myRegExp = CreateObject("VBScript.RegExp")
'Set myRegExp = New RegExp
myRegExp.IgnoreCase = False
myRegExp.Global = True
myRegExp.Pattern = reg_exp
FindReplaceRegex = myRegExp.replace(rng.Value, replace)
End Function
result
(From r In DT_Data.AsEnumerable Let ra = r.ItemArray.Select(Function (x) x.ToString.Trim.Replace("your target ",β β)).toArray() Select DT_Data.Rows.Add(ra)).CopyToDataTable()
try this after read excelfile
how can i replace all the characters ,placing those in βyour targetβ ?i can only give one character right?
May i know from where you are getting this excel data
I am just giving a scenario, if these kinds of data come, and we have to clean them and feed to queue, then how to do
yesh you can give which one you want to replace
example for if you want to replace β@β with β#β , @ is your target value and # will be destination
in this one code can i replace all the unwanted characters with ββ?
Hey @ydash999
Read the Excel data into a table.
Replace the unwanted symbols with empty string for each row.
Write the table back to the Excel.
Hope this helps.
Thanks
#nK
yeah it will
how to use replace method within for each?
in βtargetβ i can only give one character like # or @ or any other right? how to replace more than one character with"" within βtargetβ?
try this
d.xaml (10.5 KB)
if you dont use regex you can also use multiple assign statements to replace the special characters e.g.
- CurrentRow(col.ColumnName) = CurrentRow(col.ColumnName).toString.replace(β<β, ββ)
- CurrentRow(col.ColumnName) = CurrentRow(col.ColumnName).toString.replace(β>β, ββ)
and so on β¦
Hello @ydash999
you can do as below.
All the unwanted symbols are added in the below regex. If you want to add more symbols you can directly add it in the expression.
System.Text.RegularExpressions.Regex.Replace(Str, β([`β¦:>(!ββ/-])β, ββ)


ExcelAutomationDemo.zip (77.1 KB)
you can give whatever character,number, string or anything
thankss bro!seems good solution to me
thankss a lot !
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.