简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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