我需要一个Excel中的宏,它给出一个字符串值,并在单独的工作表上的列中搜索该(大约)字符串值。如果找到匹配,则标记'那一排。
我遇到的主要问题是无法访问宏中的其他工作表。
这是我的IF(OR ..)
陈述,而不是基本了解我要做的事情。我可以使用worksheetName
访问其他工作表!
=IF(OR(EXACT(P3,'List of companies'!$A$1), EXACT(P3,'List of companies'!$A$2), EXACT(P3,'List of companies'!$A$3),...., "FLAG", "")
这是我对宏的尝试
Sub searchandcompare()
Dim Worksheet As Workbook
Dim searchSheet As Worksheet
Set searchSheet = Workbook.Worksheet("List of companies")
For Each xCell In Selection
For Each searchSheet In Range("A1:A65")
If StrComp(xCell.Value, searchSheet) Then
xCell.Offset(, -15).Value = "FLAG"
Exit For
End If
Next searchSheet
Next xCell
End Sub
答案 0 :(得分:0)
试试这个:
Sub searchandcompare()
For Each xCell In Selection
For Each searchSheet In Sheets("List of companies").Range("A1:A65")
If StrComp(xCell.Value, searchSheet.Value) = 0 Then
xCell.Offset(, -15).Value = "FLAG"
Exit For
End If
Next searchSheet
Next xCell
End Sub