作者:海边的迷思萝_160 | 来源:互联网 | 2023-05-19 15:54
I need to check if a person (1, 2, 3, 4, 5) have authorization to use some product (A, B, C, D, E), so i have this: ![Check](https://img.php1.cn/3cd4a/1eebe/cd5/d05d9dfd09a56332.webp)
我需要检查一个人(1,2,3,4,5)是否有权使用某些产品(A,B,C,D,E),所以我有这个:
and have this authorizations table:
并拥有此授权表:
so i need, after insert the letter and the number, have a Yes or No Authorization.
所以我需要,插入字母和数字后,有一个是或否授权。
2 个解决方案
You can use something like this directly into your workbook (more details below) :
您可以将这样的内容直接用于您的工作簿(下面有更多详细信息):
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
First you need to set a name for your authorization table (I used "DB_Prod"), or specify the address of the table ($A$1:$C$10) and change the Sheet name into the code :
首先,您需要为授权表设置一个名称(我使用“DB_Prod”),或者指定表的地址($ A $ 1:$ C $ 10)并将Sheet名称更改为代码:
A = ThisWorkbook.Sheets("Feuil1").Range("DB_Prod").Value
A = ThisWorkbook.Sheets(“Feuil1”)。范围(“DB_Prod”)。值
Then activate macro recorder and change 2 cells color, one to green, one to red to identify the specific colors that you use and change it into the code :
然后激活宏录制器并更改2个单元格颜色,一个更改为绿色,一个更改为红色以标识您使用的特定颜色并将其更改为代码:
If ThisWorkbook.Sheets("Feuil1").Cells(i, j).Interior.Color <> 5287936
(green color)
如果ThisWorkbook.Sheets(“Feuil1”)。Cells(i,j).Interior.Color <> 5287936(绿色)
Then you can type directly into your workbook : =Get_Auth(A2,C1)
然后你可以直接输入你的工作簿:= Get_Auth(A2,C1)
Enjoy!