Image열 위치가 고정되어 있지 않은 것으로 가정하고 두 열 모두 자동으로 검색 한 후 아래 작업을 수행해야합니다. 사례 : -두 개의 서로 다른 열의 값을 고유 한 조건으로 비교
'C'열에는 'F'열의 7 자리 값을 나타내는 두 자리 값이 있습니다. 열 'C'에는 열 'F'의 8 자리 값으로 연결되는 3 자리 값이 있습니다. 'F2'와 'F3'이 21로 시작하고 Msgbox 'Error in this row'가 유효한지 확인하고 싶습니다. 'F6'과 'F7'이 함께 시작하는지 228, '이 행에 오류가 없습니다'라는 메시지가 표시됩니다.
감사합니다. 은 ++ 코드
Sub CompareColumns()
Dim lr As Long, n As Long
Dim rng As Range, cell As Range
Dim strA As String, strB As String, str As String
Dim NotMatched As Boolean
lr = Cells(Rows.Count, 1).End(xlUp).Row
'Assuming your data starts from Row2
Set rng = Range("B2:B" & lr)
str = "The following cells don't match." & vbNewLine & vbNewLine
For Each cell In rng
If cell <> "" Then
n = Len(cell.Offset(0, -1))
If n > 0 Then
strA = cell.Offset(0, -1).Text
strB = Left(cell, n)
If strA <> strB Then
NotMatched = True
str = str & cell.Offset(0, -1).Address(0, 0) & " : " &
cell.Offset(0, -1).Value & vbTab & cell.Address(0, 0) & " : " & cell.Value &
vbNewLine
End If
Else
str = str & cell.Offset(0, -1).Address(0, 0) & " : " & cell.Offset(0, -1).Value & vbTab & cell.Address(0, 0) & " : " & cell.Value & vbNewLine
End If
End If
n = 0
strA = ""
strB = ""
Next cell
If NotMatched
MsgBox str, vbInformation
Else
MsgBox "Both columns match.", vbInformation
End If
End Sub
지금까지 작성한 코드를 게시하십시오. –
"sktneer"에서 가져온 코드를 게시했습니다. –