我需要一些使用Userform更新Excelsheet中数据的帮助。通过在用户表单上创建搜索按钮并更新数据,我成功地使用了唯一的ID来搜索数据。
但是我的问题是,在修改具有唯一ID的数据后,应该在工作表中的旧数据下方的新行中使用相同的唯一ID对它进行更新。
为更加清晰起见,我在图像上附加了示例图片。
下面是我的代码,我试图创建一个新行,但无法保持旧数据不变。
Private Sub CommandButton1_Click()
Dim WB As Workbook
Set WB = Workbooks.Open("C:\Desktop\Process.xlsx")
Set ssheet = WB.Worksheets("Process1")
Dim totalrow As Long
totalrow = ssheet.Range("A1").CurrentRegion.Rows.Count
For currentrow = 2 To totalrow
If Trim(tbsno) = Trim(Cells(currentrow, 1)) Then
tbaxalant = Cells(currentrow, 2)
tbrequest = Cells(currentrow, 3)
End If
Next currentrow
End Sub
Private Sub CommandButton2_Click()
Dim WB As Workbook
Set WB = Workbooks.Open("C:\Desktop\Process.xlsx")
Set ssheet = WB.Worksheets("Process1")
ssheet.Range("A4").Select
ActiveCell.EntireRow.Insert Shift:=x1Down
Dim fvalue As Range
Set fvalue = ssheet.Range("A:A").Find(What:=Me.tbsno.Value, LookIn:=xlFormulas, LookAt:=xlWhole)
fvalue.Value = Me.tbsno
fvalue.Offset(0, 1).Value = Me.tbaxalant
fvalue.Offset(0, 2).Value = Me.tbrequest
End Sub