excel - 更新对工作表上已编辑数据的更改不起作用
问题描述
我正在尝试编辑工作表中文本框中显示的数据,我可以执行所有其他必要的操作,例如添加数据,但是我附加的代码不会使用更改更新工作表,我尝试使用 offset(0,1)但所做的只是用它正在搜索的 ID 号更改一行。Box1 是一个带有 ID 号的文本框,它是我的程序运行的主要标准。
我对 VBA 比较陌生,并试图寻找解决方案,但现在我很茫然,没有更改我的整个代码,只是为了解决可能对比我更有经验的人来说是一个简单的解决方案。
Dim findvalue As Range
Set findvalue = Sheet1.Range("A:A").Find(What:=Box1, LookIn:=xlValues)
cNum = 20
For X = 1 To cNum
findvalue = Me.Controls("Box" & X).Value(0, 1)
Set findvalue = findvalue(0, 0)
Next
解决方案
这对我来说没有太大意义,但是如果您有 20 个文本框(1 到 20),您可以使用以下语法将存储在文本框中的值写入 ID 所在范围内。我希望你能更接近解决你的问题。
Sub makeAndboxes()
Dim j As Integer
Dim tbox As MSForms.TextBox
'For the test creates 20 Textboxes with the name and value Box1, Box2, ..Box20.
'The same text is in the range("A:A") somewhere to test
For j = 1 To 20
Set tbox = UserFormBX.Controls.Add("Forms.Textbox.1", "Box" & j)
tbox.Value = tbox.Name 'Write the name in the box
Next j
Dim findvalue As Range
'If it is the "A:A" range, it will be the cell where it is found
Set findvalue = Sheet3.Range("A:A").Find(What:=UserFormBX.Controls("Box1").Value, LookIn:=xlValues)
If findvalue Is Nothing Then
MsgBox "Value: " & UserFormBX.Controls("Box1").Value & " not in Range(A:A)"
Exit Sub
End If
Dim cNum As Integer
Dim x As Integer
cNum = 20
For x = 1 To cNum
findvalue.Value = UserFormBX.Controls("Box" & x).Value & " New text"
Set findvalue = findvalue.Offset(1, 0) 'next row
Next
End Sub
推荐阅读
- c# - 如何从 TidyManaged C# 获取警告和错误消息 - HTML 解析
- python - 如何永久删除自动激活的 conda 环境?
- javascript - 无法使用 JS 将 Base 64 图像发送到 Woocommerce /product API
- read-the-docs - 如何将方程式编号放在 readthedocs 的右侧?
- mysql - mysql 最新的 Docker Desktop 3.3.0 (62916)
- powershell - 在 PowerShell 中检查打印机状态
- sql - 具有动态和静态列值的 SQL INSERT INTO TABLE
- informatica - 我有一个平面文件日期格式是 mm-dd-yyyy,我需要将其加载到表中。在表中,我的日期列为 yyyy-mm-dd
- flutter - Flutter 中 url_launcher 的问题(我无法启动网站)
- python - 循环遍历电子邮件的数据帧会产生 smtplib.SMTPRecipientsRefused 错误