我是新来的寻求帮助,但我是如此困住!.....这里请您提供任何帮助!
在excel中有一个用户窗体,该窗体具有一个列表框,该列表框从动态范围(5列,其中1个是唯一的ID号)中提取数据。用户单击记录时,它将在文本框中显示每个值,并在标签中显示ID号。参见代码:
Private Sub ListBox1_Click()
Me.Label6 = Me.ListBox1.List(ListBox1.ListIndex, 0) 'record number
Me.TextBox1 = Me.ListBox1.List(ListBox1.ListIndex, 4)'Staff name
Me.TextBox2 = Me.ListBox1.List(ListBox1.ListIndex, 1)'Strategy
Me.TextBox3 = Me.ListBox1.List(ListBox1.ListIndex, 2)'Notes
Me.TextBox4 = Me.ListBox1.List(ListBox1.ListIndex, 3)'Date
End Sub
我希望用户更改记录并更新列表框和图纸上的数据。现在的问题是它将用一个值更新工作表。它仅用一个值更新正确的记录!
User form with updated same value in all columns see rec# 5
请参见下面的代码,该代码无法正常工作:
Private Sub CMDUpdate_Click()
Dim erowa As Integer
Dim x As Integer
erowa = Application.WorksheetFunction.CountA(Sheet9.Range("A:A"))
For x = 2 To erowa
If Sheet9.Cells(x, "A").Value = Me.Label6 Then 'this is the unique ID
Sheet9.Cells(x, "B").Value = Me.TextBox1.Value 'Staff name
Sheet9.Cells(x, "C").Value = Me.TextBox2.Value 'Strategy
Sheet9.Cells(x, "D").Value = Me.TextBox3.Value 'Notes
Sheet9.Cells(x, "E").Value = Me.TextBox4.Value 'date
End If
Next
End Sub
此外,由于某种原因,如果您可以用现在很好的日期格式来帮助我,它会显示朱利安值!
我只是不知道发生了什么。我花了一整天的时间研究,观看教程,阅读博客,但似乎无法弄清楚为什么它会以相同的价值更新记录。谢谢
这是一种在Me.Label6中查找值并更新其旁边的单元格的方法
Private Sub CMDUpdate_Click()
Dim cell As Range
Set cell = sheet9.Range("A:A").Find(What:=Me.Label6.Caption, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not cell Is Nothing Then
' Column B
cell.Offset(, 1).Value = Me.TextBox1.Value 'Staff name
' Column C
cell.Offset(, 2).Value = Me.TextBox2.Value 'Strategy
' Column D
cell.Offset(, 3).Value = Me.TextBox3.Value 'Notes
' Column E
cell.Offset(, 4).Value = Me.TextBox4.Value 'date
Else
MsgBox "Record: " & Me.Label6.Caption & " not found in column A!"
End If
End Sub
让我知道它是否有效!