Problems with the match function in Excel

Source: Internet
Author: User
Tags goto range first row
excel| Function | problem
Sub Usematch ()
Dim s_p As String, e_p as String
Dim Num as Integer
num = 0
For each M in Range ("A:a")
If m.value <> "" Then
num = num + 1
Else
Exit for
End If
Next M
Erange = "B" & Num
Erange = "B2:" & Erange
N = 1
A = 2
Currange = "B" & A
Cells.select
Selection.sort Key1:=range ("A2"), Order1:=xlascending, Key2:=range ("B2") _
, Order2:=xlascending, Header:=xlguess, Ordercustom:=1, matchcase:= _
False, Orientation:=xltoptobottom, Sortmethod:=xlpinyin, dataoption1:= _
Xlsortnormal, Dataoption2:=xlsortnormal
Columns ("A:a"). Select
Selection.insert Shift:=xltoright ' left insert one column
Set Curcell = Worksheets (Sheets (1). Name). Range (Currange)
For all M in Range (Erange)
On Error GoTo ErrorHandler
If m.offset (0,-1). Value <> "" Then GoTo Mynext
If m.offset (0, 1). Value = "" Then GoTo mynext ' current cell left empty/Right cell content is empty
s_p = m.value:e_p = M.offset (0, 1). Value

pos = Application.WorksheetFunction.Match (e_p, Worksheets (1). Range (Erange), 0) ' Find the number of rows that appear in the Start column for the end point
If pos = "" Then
Curcell.offset (0,-1). Value = "NO"
GoTo Mynext ' If not found then set to ' no '
End If
Thenext:
Position = "B" & Trim (STR (POS)) ' navigates to the cell
If Range (Position). Offset (0, 1). Value = s_p Then
If Range (Position). Offset (0,-1) = "Then ' if satisfied, mark before corresponding record
Curcell.offset (0,-1). Value = N & ". A
Range (Position). Offset (0,-1). Value = N & ". B
n = n + 1
Else
Curcell.offset (0,-1). Value = "NO"
End If

Else
If Range (Position). Offset (1, 0). Value = E_p Then
pos = pos + 1
GoTo Thenext
Else
Curcell.offset (0,-1). Value = "NO"
End If
End If
MyVar = 0

Mynext:
A = a + 1
Currange = "B" & A
Set Curcell = Worksheets (Sheets (1). Name). Range (Currange)
Next
ErrorHandler:
Curcell.offset (0,-1). Value = "NO"
Resume Next
End Sub

The form is: column A and column B. The matching criterion is: query by row, and if the first row of column a cell contents equals another row of column B cell contents, check that the contents of column B cells in the first row are equal to the contents of another row of column A, if the equality is marked in front of the two rows. otherwise labeled No


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.