我试图从我设置的变量中获取最正确的字母,然后将“男性”或“女性”分配给结果。以下是我尝试过的代码片段。
Set Gender = rFirst.Offset(1, 5)
Worksheets("E'ee Details").Range("E1").Value = "=if(right(" & Gender & ",1)=""M"",""Male"",if(right(" & Gender & ",1)=""F"",""Female"",""""))"
这导致#NAME?被显示。
答案 0 :(得分:1)
您的方法涉及创建工作表方程式,然后使用Evaluate()
进行计算。这是另一种方法:
Sub jufg()
Dim Gender As Range, sexCode As String
Dim rFirst As Range
Set rFirst = Range("A1")
Set Gender = rFirst.Offset(1, 5)
sexCode = Right(Gender.Value, 1)
With Worksheets("E'ee Details").Range("E1")
If sexCode = "M" Then
.Value = "Male"
ElseIf sexCode = "F" Then
.Value = "Female"
Else
.Value = ""
End If
End With
End Sub
答案 1 :(得分:1)
修改如下
if(col[2].equals("3") || col[2].equals("4"))