今天项目组的一个同事问我如何快速的找到一个Excel中第3列和第5列的值完全重复的值,我想了想虽然Excel中自带查找重复值的功能,但是好像只能对同一列进行比较,所以就写了一个VBA进行处理,VBA非常简单,但效果不错. Sub FindDuplicatesInColumn() Dim lastRow As Long Dim matchFoundIndex As Long Dim iCntr As Long lastRow = ' 初始化临时列, 第7列用来存放结果,第8列将3 5两列的值拼接起
Private Sub Worksheet_SelectionChange(ByVal Target As Range) '可以直接sub(),不然选择就会触发vba Dim rows_count As Integer Dim rows_id As Integer Dim column_count As Integer Dim column_id As Integer column_count = Selection.Columns.Count '返回选择区域列数
1. '列号转字母(列名) Function Num2Name(ByVal ColumnNum As Long) As String On Error Resume Next Num2Name = "" '超出范围返回空,如调用Num2Name(100000) Num2Name = Replace(Cells(1, ColumnNum).Address(0, 0), "1", "") 'Cell.Address用来返回单元格的地址,参数(0,0)