gpt4 book ai didi

excel - 从文本框中获取值并插入到excel中

转载 作者:行者123 更新时间:2023-12-04 21:33:28 26 4
gpt4 key购买 nike

我制作了一个表单来从 textbox1 中获取值, textbox2 , textbox3并通过单击添加按钮将这些值输入到电子表格中。见附图:

attached picture .

但是我只能向我的表单插入一次数据,并且所有 3 行都被相同的数据填充。

Private Sub Add_Click()

Dim roww As Integer
Dim colh As Integer

For colh = 0 To 2
For roww = 0 To 2
Range("A2").Offset(colh, roww).Value = Controls("TextBox" & roww + 1).Value
Next roww
Next colh

End Sub

enter image description here

最佳答案

刚刚改进了 Michal 的答案,但我为最后一行添加了一个搜索条件,这样您就可以添加尽可能多的输入,而不会影响您以前的输入。

 Private Sub Add_Click()

Dim colh As Integer

'This is to find the last row in your input sheet1 (?) whichever sheet you are doing input.
Dim iRow as Long
Dim ws as Worksheets("Sheet1") 'whatever name of sheet you have.
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).row + 1

For colh = 1 To 3
ws.Cells(iRow , colh).Value = Controls("TextBox" & colh).Value
Next colh

End Sub

关于excel - 从文本框中获取值并插入到excel中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45770026/

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