通过更改名称值,Excel VBA userform通过组合框循环(Excel VBA userform loop through combo boxes by changing name value

编程入门 行业动态 更新时间:2024-10-24 04:39:12
通过更改名称值,Excel VBA userform通过组合框循环(Excel VBA userform loop through combo boxes by changing name value)

Excel用户窗体中有四个组合框,并带有这些值引用:

Me.cbDesc1.Value Me.cbDesc2.Value Me.cbDesc3.Value Me.cbDesc4.Value

我想要做的是循环这些组合框的值,以便数字1-4被一个变量改变,像这样...

For j = 1 to 4 cell_j_in_sheet = "Me.cbDesc" & j & ".Value" Next j

我在单元格中看到的是字符串(例如)“Me.cbDesc1.Value”,而不是在组合框中选择的实际值。 我如何指示VBA评估Me.cbDescj.Value并通过每次迭代输出cbDescj的当前内容?

如果有更好的方法来做到这一点,请告知。

I have four combo boxes in an Excel userform with these value references:

Me.cbDesc1.Value Me.cbDesc2.Value Me.cbDesc3.Value Me.cbDesc4.Value

What I want to do is loop through these combo box values so that the numbers 1-4 are changed with a variable, something like this...

For j = 1 to 4 cell_j_in_sheet = "Me.cbDesc" & j & ".Value" Next j

What I see in my cell is the string (e.g.) "Me.cbDesc1.Value" and not the actual value selected in the combo box. How do I instruct VBA to evaluate Me.cbDescj.Value and output the current contents of cbDescj through each iteration?

If there's better way to do this, please advise.

最满意答案

您可以使用表单的Controls属性:

For j = 1 to 4 cell_j_in_sheet = Me.Controls("cbDesc" & j).Value Next j

You can use the form's Controls property:

For j = 1 to 4 cell_j_in_sheet = Me.Controls("cbDesc" & j).Value Next j

更多推荐

本文发布于:2023-08-07 20:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   名称   VBA   Excel   changing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!