bossofalan
12-14-2021, 05:06 AM
I'm new to the VBA so I need help.
I want to compare the values from two columns, but there is a line break separete the contents. So what I think is that using arr1, arr2 read the cell values and split it end with the line break. Then, store it into arr3 and arr4 so that I can compare. The program would find the differnce and highlight it. Of course here I use = sign to compare because it is easiler to do so. So that, I want to first convert the font in column B to red and highlight the equal words to black. Below is my works please help! Thank you.
Sub compare()
Dim arr1, arr2, arr3, arr4
Dim rng1 As Range, rng2 As Range
'Code for select two column or range??
arr3 = Split(arr1, Chr(10))
arr4 = Split(arr2, Chr(10))
'Code for delete words after / i.e. make "Apple / JP" to "Apple" I guess
For i = LBound(arr3) To UBound(arr3)
For j = LBound(arr4) To Ubound(arr4)
If arr4(j) = arr3(i) Then arr2(j).Font.vbRed
Next j
Next i
End Sub
This is the effect I want.
29227
I want to compare the values from two columns, but there is a line break separete the contents. So what I think is that using arr1, arr2 read the cell values and split it end with the line break. Then, store it into arr3 and arr4 so that I can compare. The program would find the differnce and highlight it. Of course here I use = sign to compare because it is easiler to do so. So that, I want to first convert the font in column B to red and highlight the equal words to black. Below is my works please help! Thank you.
Sub compare()
Dim arr1, arr2, arr3, arr4
Dim rng1 As Range, rng2 As Range
'Code for select two column or range??
arr3 = Split(arr1, Chr(10))
arr4 = Split(arr2, Chr(10))
'Code for delete words after / i.e. make "Apple / JP" to "Apple" I guess
For i = LBound(arr3) To UBound(arr3)
For j = LBound(arr4) To Ubound(arr4)
If arr4(j) = arr3(i) Then arr2(j).Font.vbRed
Next j
Next i
End Sub
This is the effect I want.
29227