Vba 用字符串值中的空格替换下划线字符
这是一个相当简单的问题 我的日期变量格式如下:Vba 用字符串值中的空格替换下划线字符,vba,excel,excel-2010,Vba,Excel,Excel 2010,这是一个相当简单的问题 我的日期变量格式如下:25\u December\u 2010 我希望在VBA宏中使用一条语句或一段代码,将字符串值从:2010年12月25日转换为2010年12月25日 要想从字符串中删除下划线,请使用下面的代码 Dim strDate As String strDate = "25_December_2010" strDate = Replace(strDate,"_"," ") 我想在用于数据清理的宏中使用类似的东西,所以我接受了@simoco的答案,创建了一个简
25\u December\u 2010
我希望在VBA宏中使用一条语句或一段代码,将字符串值从:2010年12月25日
转换为2010年12月25日
要想从字符串中删除下划线
,请使用下面的代码
Dim strDate As String
strDate = "25_December_2010"
strDate = Replace(strDate,"_"," ")
我想在用于数据清理的宏中使用类似的东西,所以我接受了@simoco的答案,创建了一个简单但基本安全的宏/sub
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
strDate=Replace(strDate,“”,“)
?这是正确的!它起作用了。对不起,这个问题太基本了,我工作忙得不可开交,几乎没有时间去查。如果你想,你可以把它放在一个简单的答案,我会标记为正确的其他用户以及。再次感谢你。