下拉选择 [英] Drop down selection

查看:55
本文介绍了下拉选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


Hi

Hi



我正在寻找一些关于为excel中的单元格创建下拉选择的帮助,所以当您选择下拉框出现的单元格,您可以选择四种颜色的选项来填充单元格。

I am looking for some help on creating a dropdown selection for cells in excel so when you select the cell the dropdown box appears and you can select an option of four colours to fill the cell.



单元格已经填充了数字,我不希望这个更改,我只想选择填充颜色,所有其他数据都受到保护,所以没有人可以编辑数据单元格填充颜色的工作表有四个选项。

The cells are already refilled with numbers, I do not want this to change, I only want to select the fill colour with all the other data being protected, so nobody can edit the data on the worksheet on the cell fill colour with four options.



非常感谢任何帮助。

Any help would be very much appreciated.



亲切问候

推荐答案

标准数据验证下拉列表只能用于更改值一个单元格,而不是它的填充颜色。

The standard data validation dropdown can only be used to change the value of a cell, not its fill colour.

组合框显示文本值,而不是颜色。

And combo boxes display text values, not colours.

另一种方法是显示用户表单用户双击特定范围内的单元格。

An alternative would be to display a userform when the user double-clicks a cell in a specific range.

工作表模块中的代码:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range,Cancel As Boolean)

  ;  如果不相交(范围("A1:A5"),目标)则为Nothing然后为
       取消= True

        frmColour.Show

   结束如果

End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Range("A1:A5"), Target) Is Nothing Then
        Cancel = True
        frmColour.Show
    End If
End Sub

userform模块中的代码:

Code in the userform module:

Private Sub cmdCyan_Click()

    Active Sheet.Unprotect'密码:="秘密" b
    ActiveCell.Interior.Color = vbCyan

    ActiveSheet.Protect'密码:="秘密"

   卸载我

结束子

Private Sub cmdCyan_Click()
    ActiveSheet.Unprotect 'Password:="secret"
    ActiveCell.Interior.Color = vbCyan
    ActiveSheet.Protect 'Password:="secret"
    Unload Me
End Sub

私人子cmdGreen_Click()

    ActiveSheet.Unprotect'密码:="秘密" b
    ActiveCell.Interior.Color = vbGreen

    ActiveSheet.Protect'密码:="秘密"

   卸载我

结束子

Private Sub cmdGreen_Click()
    ActiveSheet.Unprotect 'Password:="secret"
    ActiveCell.Interior.Color = vbGreen
    ActiveSheet.Protect 'Password:="secret"
    Unload Me
End Sub

私人子cmdRed_Click()

    ActiveSheet.Unprotect'密码:="秘密" b
    ActiveCell.Interior.Color = vbRed

    ActiveSheet.Protect'密码:="秘密"

   卸载我

结束子

Private Sub cmdRed_Click()
    ActiveSheet.Unprotect 'Password:="secret"
    ActiveCell.Interior.Color = vbRed
    ActiveSheet.Protect 'Password:="secret"
    Unload Me
End Sub

私人子cmdYellow_Click()

    ActiveSheet.Unprotect'密码:="秘密" b
    ActiveCell.Interior.Color = vbYellow

    ActiveSheet.Protect'密码:="秘密"

   卸载我

结束子

Private Sub cmdYellow_Click()
    ActiveSheet.Unprotect 'Password:="secret"
    ActiveCell.Interior.Color = vbYellow
    ActiveSheet.Protect 'Password:="secret"
    Unload Me
End Sub

请参阅DropBox上的示例工作簿:
https://www.dropbox.com/s/arlqvqytbkigbe1/Colours.xlsm?dl=1

See the sample workbook on DropBox: https://www.dropbox.com/s/arlqvqytbkigbe1/Colours.xlsm?dl=1


这篇关于下拉选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆