我想比较两列的名称,但它们的格式不同,例如,一列是Xu, Boxi
; 另一个是BOXI XU
。所以我需要比较它忽略顺序和逗号而不区分大小写。
到目前为止,我可以通过在 Excel 中使用 UPPER 来解决区分大小写的部分,但无法解决顺序和逗号问题。这是我用于比较功能的 VBA 代码。
Sub Find_Matches()
Dim CompareRange As Variant, x As Variant, y As Variant
' Set CompareRange equal to the range to which you will
' compare the selection.
Set CompareRange = Range("C1:C5")
' NOTE: If the compare range is located on another workbook
' or worksheet, use the following syntax.
' Set CompareRange = Workbooks("Book2"). _
' Worksheets("Sheet2").Range("C1:C5")
'
' Loop through each cell in the selection and compare it to
' each cell in CompareRange.
For Each x In Selection
For Each y In CompareRange
If x = y Then x.Offset(0, 1) = x
Next y
Next x
End Sub
还有一点就是,如上图,循环只是 from C1 to C5
,不知道结束索引的情况下,如何让它循环到图表结束呢?