Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3065|回复: 4

[已解决]Combobox添加内容

[复制链接]
发表于 2013-5-30 14:54 | 显示全部楼层 |阅读模式
在一张工作表里添加了一个Combobox控件,想把D12:F12的内容放进去,但是区域不固定,会越来越多比如到D12:H12,最好用变量表示,返回值显示在F11,
最佳答案
2013-5-30 15:45
这个简单点。
  1. Private Sub ComboBox1_Change()
  2.     [f11] = Me.ComboBox1.Text
  3. End Sub


  4. Private Sub ComboBox1_GotFocus()
  5.     Dim arr, arrItem
  6.     Me.ComboBox1.Clear
  7.     If Len([d12]) Then
  8.         arr = Range([d12], [d12].End(xlToRight))
  9.         For Each arrItem In arr
  10.             ComboBox1.AddItem arrItem
  11.         Next
  12.         ComboBox1.DropDown
  13.     End If
  14. End Sub
复制代码
111.jpg

新建 Microsoft Office Excel 工作表.rar

9.19 KB, 下载次数: 4

发表于 2013-5-30 15:43 | 显示全部楼层
  1. Private Sub ComboBox1_Click()
  2.     [f11] = Me.ComboBox1.Text
  3. End Sub

  4. Private Sub ComboBox1_GotFocus()
  5.     Dim arr, arrItem
  6.     Me.ComboBox1.Clear
  7.     If Len([d12]) Then
  8.         arr = Range([d12], [d12].End(xlToRight))
  9.         For Each arrItem In arr
  10.             ComboBox1.AddItem arrItem
  11.         Next
  12.         ComboBox1.DropDown
  13.     End If
  14. End Sub

  15. Private Sub ComboBox1_LostFocus()
  16.     [f11] = Me.ComboBox1.Text
  17. End Sub
复制代码
回复

使用道具 举报

发表于 2013-5-30 15:45 | 显示全部楼层    本楼为最佳答案   
这个简单点。
  1. Private Sub ComboBox1_Change()
  2.     [f11] = Me.ComboBox1.Text
  3. End Sub


  4. Private Sub ComboBox1_GotFocus()
  5.     Dim arr, arrItem
  6.     Me.ComboBox1.Clear
  7.     If Len([d12]) Then
  8.         arr = Range([d12], [d12].End(xlToRight))
  9.         For Each arrItem In arr
  10.             ComboBox1.AddItem arrItem
  11.         Next
  12.         ComboBox1.DropDown
  13.     End If
  14. End Sub
复制代码
回复

使用道具 举报

发表于 2013-5-30 15:47 | 显示全部楼层
鼠标移动COMBOBOX时就下拉选择。
  1. Private Sub ComboBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  2.     Me.ComboBox1.DropDown
  3. End Sub

  4. Private Sub ComboBox1_GotFocus()
  5.     Dim arr, arrItem
  6.     Me.ComboBox1.Clear
  7.     Me.ComboBox1.ListStyle = fmListStylePlain
  8.     If Len([d12]) Then
  9.         arr = Range([d12], [d12].End(xlToRight))
  10.         For Each arrItem In arr
  11.             ComboBox1.AddItem arrItem
  12.         Next
  13.         ComboBox1.DropDown
  14.     End If
  15. End Sub
复制代码
回复

使用道具 举报

发表于 2013-5-30 15:48 | 显示全部楼层
组合框.rar (19.23 KB, 下载次数: 20)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-18 12:02 , Processed in 0.281348 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表