我有一个设置与板材中的列列d和重置价值的唯一标识符F.我需要:Excel的VBA - 搜索,偏移,更换
- 遍历所有序列号在片
settings
列d - 找到具有相同序列的行中片
test
塔A - 得到
settings
F列 - 替换值替换在列B中的数据上
test
片,在同一行中作为先前击发阻铁高等教育委员会串行
听起来很简单,但与下面的代码定义for
和to
语句时,我得到一个类型不匹配错误。
Sub Replace_List()
Dim rList As Range, cell As Range, n As Long
Application.ScreenUpdating = False
With ThisWorkbook.Sheets("Settings")
Set rList = .Range("D4", .Range("D" & Rows.Count).End(xlUp))
End With
For Each cell In rList
For n = cell.Value To cell.Offset(0, 2).Value Step 1
ThisWorkbook.Sheets("test").Columns("B:B").Replace What:=n, _
Replacement:=cell.Offset(0, 2).Value, _
LookAt:=xlWhole
Next n
Next cell
Application.ScreenUpdating = True
MsgBox "Replaced all items from the list.", vbInformation, "Replacements Complete"
End Sub
任何指针,我在做什么错误在这里赞赏。 谢谢, A2K
编辑 如下截图:
当cell崩溃时'cell.Value'和'cell.Offset(0,2).Value'的值是什么? – YowE3K
'cell.value'是它应该查找的序列号,而'cell.offset(0,2).value'是替换值 – Armitage2k
但是它崩溃时的值是什么?例如。它是否大于2,147,486,647? – YowE3K