从string中删除文本和保持领先的数字
我试图find一种方法,从包含前导号码的单元格中删除文本string,因为我需要的只是数字,以便在数据透视表中使用它。
这是一个数据的例子。
5 or more times 1 time 3 times 2 times
该数据在“BI”列中find,并存储在名为“DB”的工作表中。
我有一个macros从date/时间格式的列删除时间,如果我可以运行一个接一个,这将是伟大的。
这是从date/时间删除时间的代码。
Sub ToDate() Dim LR As Long, i As Long Sheets("DB").Select LR = Range("N" & Rows.Count).End(xlUp).Row For i = 2 To LR With Range("N" & i) .NumberFormat = "mm/dd/yyy" .Value = DateValue(.Value) End With Next i Sheets("Tasks").Select GoTo Fin: Fin: MsgBox ("Process Completed") End Sub
如果号码使用后总有空格
' Check that cell has a value if .Value <> "" Then .Value = Left(.Value,Instr(.Value," ")-1) Endif
使用-1来删除空间
这将返回string开头的所有内容,直到空格字符。 - 1
重要的原因是你不想在你的最终结果中使用空格字符。
With Range("BI" & i) .Value = Left(.Value, InStr(.Value, " ") - 1) End With
这也将工作:
if .Value <> "" Then .Value = Split(.Value, " ")(0) Endif