简体   繁体   English

Excel:是否可以将多个ComboBox输出聚合到单个Cell中?

[英]Excel: Is it possible to converge several ComboBox outputs into a single Cell?

Context : My Excel worksheet consists of a userform that outputs to several sheets. 上下文 :我的Excel工作表包含一个用户表单,该用户表单输出到多个工作表。 A function of this userform is a date selector, that is desired to output to a single cell. 此用户窗体的功能是日期选择器,希望将其输出到单个单元格。 However, due to the nature of its design (Obtained from a gentleman from this particular site, Doug Glancy) it consists of three comboboxes. 但是,由于其设计的性质(从该特定站点的一位绅士Doug Glancy获得),它由三个组合框组成。

It is displayed as : 显示为

[ComboBox1: Day] [ComboBox2: Month] [ComboBox3: Year] [ComboBox1:天] [ComboBox2:月] [ComboBox3:年]

Here is an image for visual reference 这是供参考的图像

Is there any particular method of forcing a concrescence from several outputs into a single cell? 是否有任何强制从多个输出到单个单元的融合的特定方法? And if not, what would be an alternative method for accomplishing a similar result? 如果没有,那么实现相似结果的替代方法是什么?

Edit: Here is my current code for transmitting data from the userform: 编辑:这是我当前用于从用户表单传输数据的代码:

    Sub Transfer()

Dim emptyRow As Long

'Make Sheet2 active
Sheet2.Activate

'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("B:B")) + 1

'Transfer information
Cells(emptyRow, 2).Value = TextBoxSON.Value
Cells(emptyRow, 3).Value = TextBoxJobDescription.Value
Cells(emptyRow, 4).Value = TextBoxCustomer.Value
Cells(emptyRow, 5).Value = TextBoxQuantity.Value
Cells(emptyRow, 6).Value = TextBoxDateRequired.Value

Dim LR As Integer
LR = Range("B" & Rows.Count).End(xlUp).Row
Application.EnableEvents = False
Range("A4:BB" & LR).Sort Key1:=Range("A4"), Order1:=xlAscending, _
    Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Application.EnableEvents = True

End Sub

Edit: Big thanks to CLR for the answer: 编辑:非常感谢CLR的答案:

mydate = DateSerial(cboYear.Value, cboMonth.Value, cboDay.Value)
Cells(emptyRow, 6).Value = mydate

This code enables the data to be output exactly as desired. 此代码使数据能够完全按要求输出。 Hope this helps anyone in the future. 希望这对将来的任何人有帮助。

( Irrelevant (But seemingly necessary) information : Hey, I'm a new SO user. After hours (and hours) of trying to find and understand this problem, I have not arrived to any possible conclusion and, with the angry hands of the clock pointing furiously at me, I am forced to (shamefully) ask this question. 无关(但似乎是必要的)信息 :嘿,我是新用户。经过数小时(数小时)的查找和理解此问题的努力,我还没有得出任何可能的结论,并且,时钟疯狂地指着我,我被迫(可耻地)问这个问题。

I am not Excel proficient nor VBA literate. 我不是精通Excel或VBA的人。 However, I have been slowly learning the language through sites such as HomeandLearn.org to overcome my difficulties but seemingly to no avail on this particular problem. 但是,我一直在通过HomeandLearn.org等网站来慢慢学习该语言,以克服我的困难,但似乎对这个特定问题没有用。 I must apologise in advance for any inappropriate use or misuse of terminology or any other uninformed misapprehension that has been made in my above question. 对于以上问题中出现的任何不当使用或误用术语或任何其他不知情的误解,我必须提前道歉。 I have attempted to familiarise myself with the community and the rules of this site before asking this question and have searched extensively for an answer. 在提出这个问题之前,我试图使自己熟悉社区和该站点的规则,并进行了广泛的搜索以寻找答案。

Any assistance would be appreciated. 任何援助将不胜感激。 Thank you.) 谢谢。)

This? 这个?

MyDate = ComboBox1.Value & ComboBox2.Value & ComboBox2.Value
Cells(emptyRow, 7).Value = MyDate

If you want the cell to contain just the text within the 3 boxes, then use: 如果要使单元格仅在三个框中包含文本,请使用:

 mydate = ComboBoxDay.Value & ComboBoxMonth.Value & ComboBoxYear.Value
 Cells(2, 7).Value = mydate

However, a more useful approach might be to populate the cell with an actual date: 但是,更有用的方法可能是使用实际日期填充单元格:

 mydate = DateSerial(ComboBoxYear.Value, ComboBoxMonth.Value, ComboBoxDay.Value)
 Cells(2, 7).Value = mydate

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

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