考虑到用窗体和控件在这里不方便,就用INPUTBOX来代替了 Sub xm() Dim xm$, ys1%, ys%, rn As Range xm = InputBox("请输入要查询的姓名,并输入显示背景颜色代码,例如:张三,1" & vbCr & "红色 绿色 蓝色 黄色 紫色 青色 桔色") xm = Replace(xm, ",", ",") If IsNumeric(Split(xm, ",")(1)) Then If InStr(xm, ",") Then ys1 = Split(xm, ",")(1) Select Case ys1 Case 1 ys = 3 Case 2 ys = 4 Case 3 ys = 5 Case 4 ys = 6 Case 5 ys = 7 Case 6 ys = 8 Case Else ys = 46 End Select End If For Each rn In SUsedRange If Value = Split(xm, ",")(0) Then IColorIndex = ys Next Else MsgBox "输入有误,请重新输入" End IfEnd Sub