考虑到用窗体和控件在这里不方便,就用INPUTBOX来代替了
Sub xm()
Dim xm$, ys1%, ys%, rn As Range
xm = InputBox("请输入要查询的姓名,并输入显示背景颜色代码,例如:张三,1" & vbCr & "1.红色 2.绿色 3.蓝色 4.黄色 5.紫色 6.青色 7.桔色")
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 Sheet1.UsedRange
If rn.Value = Split(xm, ",")(0) Then rn.Interior.ColorIndex = ys
Next
Else
MsgBox "输入有误,请重新输入"
End If
End Sub
追问没看懂啊,能不能按我的原意思去做?发个excel原件给我。
本回答被网友采纳