gpt4 book ai didi

vba - Excel VBA 替换问号

转载 作者:行者123 更新时间:2023-12-02 19:21:47 25 4
gpt4 key购买 nike

我编写了 VBA 代码来查找和替换工作簿中所有工作表中的问号。但是它不起作用,任何人都可以帮我看看我哪里出了问题吗?

Sub ReplaceQM()

Dim lRow As Long
Dim lCol As Long

totalSheet = ThisWorkbook.Sheets.Count

MsgBox totalSheet
For x = 1 To totalSheet


lRow = ThisWorkbook.Sheets(x).Cells(Rows.Count, 1).End(xlUp).Row
lCol = ThisWorkbook.Sheets(x).Cells(1, Columns.Count).End(xlToLeft).Column


For Z = 1 To lRow
For i = 1 To lCol

getPos = InStr(1, ThisWorkbook.Sheets(x).Cells(Z, i).Value, "~?")

If getPos > 0 Then

ThisWorkbook.Sheets(x).Cells(Z, i).Value = Replace(ThisWorkbook.Sheets(x).Cells(Z, i).Value, "~?", " ")

End If

Next i
Next Z
Next x
End Sub

最佳答案

您最好使用 Excel 的范围内替换功能:

For Each ws In ThisWorkbook
ws.UsedRange.Cells.Replace what:="~?", Replacement:=" ", LookAt:=False, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Next ws

关于vba - Excel VBA 替换问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40335527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com