I am new to VBA. I have job in my hand to improve performance of VBA code. To improve performance of the code, I have to read entire row and compare it with another row. Is there any way to do this in VBA?
Pseudocode:
sheet1_row1=read row1 from sheet1
sheet2_row1=read row1 from sheet2
if sheet1_row1 = sheet2_row1 then
print "Row contains same value"
else
print "Row contains diff value"
end if
Compare Two Rows in Google Sheets You can also compare two rows using conditional formatting in Google Sheets. Select the data range you want to compare (here, C2:I3), and in the Menu, go to Format > Conditional formatting.
For your specific example, here are two ways...
Case Insensitive:
MsgBox [and(1:1=2:2)]
Case Sensitive:
MsgBox [and(exact(1:1,2:2))]
...
Below are generalized functions to compare any two contiguous ranges.
Case Insensitive:
Public Function RangesEqual(r1 As Range, r2 As Range) As Boolean
RangesEqual = Evaluate("and(" & r1.Address & "=" & r2.Address & ")")
End Function
Case Sensitive:
Public Function RangesEqual(r1 As Range, r2 As Range) As Boolean
RangesEqual = Evaluate("and(exact(" & r1.Address & "," & r2.Address & "))")
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With