VBA Excel 对比两列数据

时间:2020-12-27 17:01:36

使用 C# 写的数字转字母

private string ToColumn(int p)
{
if (p > )
{
char A = (char)('A' + (p - ) / - );
char B = (char)('A' + (p - ) % );
return new string(new char[] { A, B });
}
else
return ((char)('A' + (p - ))).ToString();
}
Sub Md()
'
' Macro1 Macro
' 宏由 BX 录制,时间: 2012-6-8
' 宏中的列数可以输入 A - IV 也可以输入 1-256
'
Dim i%, j%, i1%, j1%, i2%, j2%
myi = UCase(InputBox("第一列"))
myj = UCase(InputBox("第二列"))
'
'************************************ If myi Like "[A-Z]" Then
i = Asc(myi) -
ElseIf myi Like "[A-I][A-Z]" Then
i = (Asc(Left(myi, )) - ) * + Asc(Right(myi, )) -
ElseIf IsNumeric(myi) Then
i = myi
Else
i =
End If
If myj Like "[A-Z]" Then
j = Asc(myj) -
ElseIf myj Like "[A-I][A-Z]" Then
j = (Asc(Left(myj, )) - ) * + Asc(Right(myj, )) -
ElseIf IsNumeric(myj) Then
j = myj
Else
j =
End If 'ucase 转大写 upper lcase 转小写 lower i2 = 'i列颜色
j2 = 'j列颜色 '在上面更改哪两列对比,对比相同后的背景色
'************************************
'以下内容不用修改
Application.ScreenUpdating = False
If i = j Then j = i +
For i1 = To Cells(, i).End().Row
For j1 = To Cells(, j).End().Row
If Cells(i1, i).Value = "" Then Exit For
If Cells(j1, j).Interior.ColorIndex <> And Cells(i1, i).Value = Cells(j1, j).Value Then
Cells(i1, i).Interior.ColorIndex = i2
Cells(j1, j).Interior.ColorIndex = j2
Exit For
End If
Next
Next
Application.ScreenUpdating = True
MsgBox "对比完成!" & vbCrLf & "刚才对比的是 " & i & " 列和 " & j & " 列的数据"
' 如果不想弹出提示 把上面前面加上 ' 英文单引号即可
End Sub