我正在寻找我的项目的解决方案。
我有源数据workbook_src
和目标数据worbook_dest
。 workbook_src
中的数字格式为="123456789"
。我的目标是将workbook_src
设为只读,将带有数字的行复制到内存中,将其清除为仅数字,然后将特殊值粘贴到workbook_dest
作为值。
以只读方式打开workbook_src
Dim src As Workbook
Set src = Workbooks.Open("C:\xxx.xlsx", True, True)
ThisWorkbook.Activate
清除数字的功能
Function GetNumeric(CellRef As String)
Dim StringLength As Integer
StringLength = Len(CellRef)
For i = 1 To StringLength
If IsNumeric(Mid(CellRef, i, 1)) Then Result = Result & Mid(CellRef, i, 1)
Next i
GetNumeric = Result
End Function
但是我无法在整个行上应用此功能
答案 0 :(得分:0)
找到解决方案
Function cleanString(str As String) As String
Dim ch, bytes() As Byte: bytes = str
For Each ch In bytes
If Chr(ch) Like "[A-Z.a-z 0-9]" Then cleanString = cleanString & Chr(ch)
Next ch
End Function
Sub btn_CleanAll()
Dim rng As Range
For Each rng In Sheets("Sheet1").Range("A2:A30000").Cells
rng.Value = cleanString(rng.Value)
Next
MsgBox "Done"
End Sub