Excel 与按钮结合使用的组合框
我有一个组合框;进行选择时,用该值填充链接的单元格。我想重复这个过程,但每次都要直接填充下面的单元格。我曾想过使用一个按钮,但不确定如何创建宏来实现这一点。非常感谢您的帮助。下面的单元格-我想您希望将链接的单元格更改为下一行吗?Excel 与按钮结合使用的组合框,excel,vba,Excel,Vba,我有一个组合框;进行选择时,用该值填充链接的单元格。我想重复这个过程,但每次都要直接填充下面的单元格。我曾想过使用一个按钮,但不确定如何创建宏来实现这一点。非常感谢您的帮助。下面的单元格-我想您希望将链接的单元格更改为下一行吗? 这是有效的;代码被注释 Option Explicit Dim insw& ' global needed because changing the row calls the _Change Sub. ' This is an "in-process" sw
这是有效的;代码被注释
Option Explicit
Dim insw& ' global needed because changing the row calls the _Change Sub.
' This is an "in-process" switch.
Sub combobox1Reset() ' reset to B5
ComboBox1.Clear
ComboBox1.AddItem "One"
ComboBox1.AddItem "Two"
ComboBox1.AddItem "Three"
insw = 1
ComboBox1.LinkedCell = Cells(5, 2).Address ' B5
insw = 0
End Sub
Private Sub ComboBox1_Change()
Dim iRow&, iCol&, s1$, zCell As Range
If insw Then Exit Sub ' skip row change
s1 = ComboBox1.LinkedCell ' old addr
Set zCell = Range(s1) ' get row, col
iRow = zCell.Row + 1 ' increment
iCol = zCell.Column
insw = 1 ' skip row change
ComboBox1.LinkedCell = Cells(iRow, iCol).Address
insw = 0
End Sub