简体   繁体   English

Excel VBA,循环查找空单元格并向其添加组合框值

[英]Excel VBA, looping to find empty cell and add combobox value to it

So far what I have is this : 到目前为止,我所拥有的是:

Dim Check As Long

Check = Cells(Rows.Count, "B").End(xlUp).Row

For i = Check To 1 Step -1
If Range("B" & i).Value = "" Then
  Range("B" & i).Value = ComboBox2.Value
End If
Next i

Essentially I am trying to add multiple comboboxes and text boxes to the next empty lines and I think that would be with offsets as well. 本质上,我试图将多个组合框和文本框添加到下一个空行中,我认为这也将包含偏移量。

In the interest of avoiding 'drive-by answers' through comments try this. 为了避免通过注释产生“过失答案”,请尝试这样做。

cells(rows.count, "B").end(xlup).offset(1, 0) = ComboBox2.Value

That should replace all of your code in a private worksheet code sub. 那应该替换私有工作表代码子中的所有代码。 If it is not a private worksheet code sheet then, 如果它不是私有工作表代码表,

with worksheets("Sheet1")
   .cells(.rows.count, "B").end(xlup).offset(1, 0) = ComboBox2.Value
end with

... in a public module code sheet. ...在公共模块代码表中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM