您好我有一个电子表格和一些用户表单来查看控制股票。我有一个问题,我需要通过一些搜索代码找到一行后编辑一个单元格值。
电子表格:
6列:条形码编号,批号,项目代码,描述,数量,最佳之前
无限行
原始代码我必须搜索并删除一行(Works Fine):
Sub DeleteRows()
Dim ws As Worksheet
Dim strSearch As String
Dim aCell As Range
On Error GoTo Err
'~~> Set the sheet where you want to search the IMEI
Set ws = Sheets("Stock Sheet")
With ws
'~~> Get the value which you want to search
strSearch = TextBox1.Value
'~~> Column A is Column 1 so Column B is 2. This is where we are searching
'~~> xlWhole is used in the code below so that we find a complete match
'~~> xlPart is supposed to be used when you are finding a partial match.
Set aCell = .Columns(1).Find(What:=strSearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
'~~> Check if we found the value
If Not aCell Is Nothing Then
'~~> get the row of the cell where we found the match and delete it
.Rows(aCell.Row).Delete
Else '<~~ If not found
MsgBox "Pallet Number not Found"
End If
End With
Exit Sub
Err:
MsgBox Err.Description
End Sub
但我想更改.Rows(aCell.Row)。删除,以便它不是删除完整的行,而是希望它将第5列(qty)中的单元格值更改为基于输入到Textbox2的值表格
不确定我是否已正确解释任何帮助将不胜感激
干杯
答案 0 :(得分:0)
尝试如下:
If Not aCell Is Nothing Then
aCell.Offset(0, 4).Value = TextBox2.Value
Else
MsgBox "Pallet Number not Found"
End If
我只是展示一个要修改的部分。