Excel VBA用户表单更新button

如果目标单元格旁边的单元格中有值,则更新button将无法在此代码中find问题。

Private Sub CommandButton3_Click() Dim irow As Long, _ wS As Worksheet, _ NextRow As Long, _ cF As Range Set wS = Worksheets("stock") With wS With .Range("A:A") Set cF = .Find(What:=Me.ComboBox2.value, _ After:=.Cells(1, 1), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False, _ SearchFormat:=False) End With If Not cF Is Nothing Then If cF.Offset(0, 1) <> vbNullString Then Set cF = cF.End(xlToRight).Offset(0, 25) cF.value = Me.TextBox2.value + .Cells(cF.row, "AA").value End If Else .Cells(cF.row, "AA").value = Me.TextBox2.value + .Cells(cF.row, "AA").value End If 

End With End Sub

如果目标单元格是AA2那么在Z2或B2中应该有值,否则什么都不会发生。

刚刚添加了ELSE语句,但是在AB列中的更新值不在AA中

形成

我只是在hit n试用的基础上做到了这一点,它的工作原理

  `Private Sub CommandButton3_Click() Dim irow As Long, _ wS As Worksheet, _ NextRow As Long, _ cF As Range Set wS = Worksheets("stock") With wS With .Range("A:A") Set cF = .Find(What:=Me.ComboBox2.value, _ After:=.Cells(1, 1), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False, _ SearchFormat:=False) .Cells(cF.row, "AA").value = Me.TextBox2.value + .Cells(cF.row, "AA").value End With End Sub`