Sub Match() Dim var As Variant, iSheet As Integer, iRow As Long, iRowL As Long, bln As Boolean, rng1 As Range, rng2 As Range, i As Long, j As Long If Not IsEmpty(rng1) Then For i = 1 To Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row Set rng1 = Sheets("Sheet1").Range("A" & i) For j = 1 To Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Row Set rng2 = Sheets("Sheet1").Range("C" & j) bln = False var = Application.Match(rng1.Value, rng2, 0) If Not IsError(var) Then bln = True Exit For Exit For End If Set rng2 = Nothing Next j Set rng1 = Nothing Next i For i = 1 To Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row Set rng1 = Sheets("Sheet1").Range("A" & i) If bln = False Then Cells(rng1).Font.Bold = False Else Cells(rng1).Font.Bold = True End If Next i End If Application.ScreenUpdating = True End Sub
Sub CompareAndHighlight() Dim rng1 As Range, rng2 As Range, i As Long, j As Long For i = 1 To Sheets("sheet1").Range("C" & Rows.Count).End(xlUp).Row Set rng1 = Sheets("sheet1").Range("C" & i) For j = 1 To Sheets("sheet2").Range("C" & Rows.Count).End(xlUp).Row Set rng2 = Sheets("sheet2").Range("C" & j) If StrComp(Trim(rng1.Text), Trim(rng2.Text), vbTextCompare) = 0 Then rng1.Interior.Color = RGB(255, 255, 0) End If Set rng2 = Nothing Next j Set rng1 = Nothing Next i End Sub
我想数据列A和C列的数据进行比较
但是面临的挑战是,如果有一个匹配,那么我需要从C柱细胞移动到B列的相应行。
不幸的是我不能发布图片,我希望这是足够清晰的人来支持我?
我已经即兴使用“代码片段中显示的数据看起来应该假设他们被安排在列AB和C
Before A12334 A12352 A12335 A12353 A12336 A12339 A12337 A12340 A12338 A12341 A12339 A12354 A12340 A12355 A12341 A12356 A12342 A22354 A12343 A22356 A12344 A22358 A12345 A22360 A12346 A22362 A12347 A22364 A12348 A22366 A12349 A22368 A12350 A22370 A12351 A22372 A12352 A12357 A12353 A12358 A12354 A12334 A12355 A12335 A12356 A12336 A12357 A12337 A12358 A12338 A12359 A22370 A12360 A22372 A12361 A12361 After: A12334 A12334 A12335 A12335 A12336 A12336 A12337 A12337 A12338 A12338 A12339 A12339 A12340 A12340 A12341 A12341 A12342 A22354 A12343 A22356 A12344 A22358 A12345 A22360 A12346 A22362 A12347 A22364 A12348 A22366 A12349 A22368 A12350 A22370 A12351 A22372 A12352 A12352 A12353 A12353 A12354 A12354 A12355 A12355 A12356 A12356 A12357 A12357 A12358 A12358 A12359 A22370 A12360 A22372 A12361 A12361