我在同一个工作簿中有两个工作表,工作表(“送达地址”)存储原始数据,工作表(“送达证书”)供用户输入要查找的字符串,如下代码。
Private Sub OpenAddress()
Dim addressNum As Integer
Dim addressString As String
Dim name As String
Dim findCell As Range
Count = TB1.Value
'TB1.Value is the string which type by user
Set findCell = Worksheets("送達地址").Columns("A").Cells.Find(what:=Count, lookat:=xlWhole, LookIn:=xlValues)
If findCell Is Nothing Then
MsgBox "not found"
isPass = False
Exit Sub
End If
For i = 1 To People
S = 2
With Worksheets("送達地址")
.findCell.Offset(0, 1).Value = name
.findCell.Offset(0, 2).Value = addressNum
.findCell.Offset(0, 3).Value = addressString
End With
With Worksheets("送達證書")
.Cells(S, 1).Value = name
.Cells(S, 3).Value = addressNum & " " & addressString
S = S + 1
i = i + 1
End With
Next i
S = 2
End Sub
问题是,变量findCell导致返回您键入的字符串而不是其地址。
例如:您想查找字符串“ 1”的位置,但是findCell返回“ 1” 而不是返回地址“ 1”。
答案 0 :(得分:0)
它实际上是返回一个范围对象(一个单元格),当您将鼠标悬停在其上方时,将显示该单元格的值。您不需要第一个With语句,findcell.offset将在前面没有“。”的情况下工作。