我需要检查一个人(1,2,3,4,5)是否有权使用某些产品(A,B,C,D,E),所以我有这个:
并拥有此授权表:
所以我需要,在插入字母和数字后,有一个是或否授权。
答案 0 :(得分:1)
将公共函数粘贴到工作簿中的vba模块中,然后直接在工作表中将其用作公式“getAuth(...)”。
使用的参数:
Public Function getAuth(Letter As Range, Number As Range, _
AuthRange As Range, YesColor As Range) As String
Dim rng As Range
With AuthRange
Set rng = .Cells(WorksheetFunction.Match(Number, .Columns(1), 0), _
WorksheetFunction.Match(Letter, .Rows(1), 0))
getAuth = IIf(rng.Interior.Color = YesColor.Interior.Color, "Yes", "No")
End With
End Function
答案 1 :(得分:0)
您可以直接在工作簿中使用此类内容(以下详细信息):
Public Function Get_Auth(ByVal User As String, ByVal Product As String) As String
Dim A()
A = ThisWorkbook.Sheets("Feuil1").Range("DB_Prod").Value
For i = LBound(A, 1) To UBound(A, 1)
For j = LBound(A, 2) To UBound(A, 2)
If A(i, 1) <> User And A(1, j) <> Product Then
Else
'If interior is different of red (use macro recorder to get your own color reference)
If ThisWorkbook.Sheets("Feuil1").Cells(i, j).Interior.Color <> 255 Then
'If interior is different of green
If ThisWorkbook.Sheets("Feuil1").Cells(i, j).Interior.Color <> 5287936 Then
'Not handled
Else
Get_Auth = "Yes"
End If
Else
Get_Auth = "No"
End If
End If
Next j
Next i
End Function
首先您需要为授权表设置一个名称(我使用“DB_Prod”),或者指定表的地址($ A $ 1:$ C $ 10)并更改工作表名称进入代码:
A = ThisWorkbook.Sheets("Feuil1").Range("DB_Prod").Value
然后激活宏录制器并将2个单元格颜色,一个更改为绿色,一个更改为红色以识别您使用的特定颜色并将其更改为代码:
If ThisWorkbook.Sheets("Feuil1").Cells(i, j).Interior.Color <> 5287936
(绿色)
然后您可以直接在工作簿中输入:=Get_Auth(A2,C1)
享受!