用string值中的空格replace下划线字符
这是一个相当简单的问题。
我有一个datevariables格式如: 25_December_2010
我想要一个语句或VBA macro
中的一段代码,将该string值从: 25_December_2010
为25 December 2010
。
以某种方式能够从String
值中删除underscores
….
正如我在评论中提到的,使用下面的代码:
Dim strDate As String strDate = "25_December_2010" strDate = Replace(strDate,"_"," ")
我想要一个类似的macros我用于数据清理,所以我采取了@ simoco的答案,并创build了一个简单,但主要是安全的macros/子。
Sub ConvertSpaceToUnderscore() Dim strCellValue As String ' Use basic error handling if more than 1 cell is selected, or ' possibly if something that isn't a cell is selected. On Error GoTo SelectionTooBig strCellValue = Selection.Value strCellValue = Replace(strCellValue, " ", "_") Selection.Value = strCellValue On Error GoTo 0 ' Exit the sub if things went well Exit Sub SelectionTooBig: MsgBox "Please select one cell at a time.", vbCritical, "Selection too large" End Sub