VBA Excel compares two columns of data

Source: Internet
Author: User

Sub Md ()"'Macro1 Macro'macro recorded by BX, time: 2012-6-8'the number of columns in the macro can be entered A-iv or you can enter 1-256'Dim i%, j%, i1%, j1%, i2%, j2%myi= UCase (InputBox ("first column")) Myj= UCase (InputBox ("second column"))"'************************************If myi like"[A-z]"Theni= ASC (myi)- -ElseIf myi like"[A-i][a-z]"Theni= (ASC (left (myi,1)) - -) * -+ ASC (Right (myi,1)) - -ElseIf isnumeric (myi) Theni=Myielsei=1End ifif Myj like"[A-z]"Thenj= ASC (Myj)- -ElseIf Myj like"[A-i][a-z]"Thenj= (ASC (left (Myj,1)) - -) * -+ ASC (Right (Myj,1)) - -ElseIf isnumeric (myj) Thenj=Myjelsej=2End If'UCase to uppercase upper LCase turn lowercase lowerI2= +      'i-Column colorJ2 = +      'column J Color'change which two columns compare to the same background color'************************************'The following does not have to be modifiedApplication.ScreenUpdating =Falseif i= J Then J = i +1For I1=1To Cells (30000, i). End (3). Rowfor J1=1To Cells (30000, j). End (3). Rowif Cells (I1, i). Value=""Then Exit forif Cells (J1, J). Interior.ColorIndex<> +and Cells (I1, i). Value =Cells (J1, J). Value Thencells (I1, i). Interior.ColorIndex=I2cells (J1, J). Interior.ColorIndex=j2exit forend ifnextnextapplication.screenupdating=Truemsgbox "The comparison is complete! "& VbCrLf &"It's just a comparison."& I &"columns, and"& J &"columns of data"'If you don't want to pop up a hint, add the preceding'single quotes in English end Sub

VBA Excel compares two columns of data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.