gpt4 book ai didi

excel - 在用户窗体中编辑电子表格上的文本

转载 作者:行者123 更新时间:2023-12-04 22:12:32 24 4
gpt4 key购买 nike

我有以下代码,它允许我根据两个组合框的值从电子表格中选择文本。
问题是;在用户表单上进行编辑时如何在电子表格上进行编辑?

Private Sub CommandButton1_Click()
Dim s As Worksheet
Set s = ActiveSheet ' use for active sheet
'Set s = Worksheets("Sheet1") ' use for a specific sheet
For row = 1 To s.Cells(s.Rows.Count, 1).End(xlUp).row
If s.Cells(row, "A").Value = ComboBox1.Value And _
s.Cells(row, "B").Value = ComboBox2.Value Then
TextBox1.Value = s.Cells(row, "C").Value
TextBox2.Value = s.Cells(row, "D").Value
TextBox3.Value = s.Cells(row, "E").Value
TextBox4.Value = s.Cells(row, "F").Value
End If
Next
End Sub

最佳答案

假设“行”是一个模块级变量(在模块顶部声明),这就是您所需要的,假设您有一个名为 CommandButton2 的按钮,您想要单击它来保存数据:

Private Sub CommandButton2_Click()
s.Cells(row, "C").Value = TextBox1.Value
s.Cells(row, "D").Value = TextBox2.Value
s.Cells(row, "E").Value = TextBox3.Value
s.Cells(row, "F").Value = TextBox4.Value
End Sub

关于excel - 在用户窗体中编辑电子表格上的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71845326/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com