首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用户表单列表框(多个协议),用于编辑值和更新工作表和列表

用户表单列表框(多个协议),用于编辑值和更新工作表和列表
EN

Stack Overflow用户
提问于 2020-01-31 02:29:38
回答 1查看 881关注 0票数 0

我在Excel中有一个用户表单,它有一个从动态范围(5列,1是唯一ID号)中提取数据的列表框。

当用户单击记录时,它会在文本框中显示每个值,并在标签中显示ID号。

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
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

由于某些原因,日期格式也会显示Julian值!

我花了一整天的时间研究,看教程,读博客。

EN

回答 1

Stack Overflow用户

发布于 2020-01-31 04:28:46

这是一种在Me.Label6中查找值并更新其旁边单元格的方法

代码语言:javascript
运行
复制
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

如果有效,请让我知道!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59992339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档