Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 对内容进行排序以匹配列上的信息_Excel_Sorting_Excel Formula_Vba - Fatal编程技术网

Excel 对内容进行排序以匹配列上的信息

Excel 对内容进行排序以匹配列上的信息,excel,sorting,excel-formula,vba,Excel,Sorting,Excel Formula,Vba,看这个例子: 我在第一栏有所有可能的信息,第二栏只有物理上存在的信息。从第二列开始的行显示存在的信息 有没有办法把事情弄清楚 我试过按字母顺序排序,但并没有像我演示的那样有效。还要注意,这只是一个示例。 在我的主要工作表中,事情之间并不十分接近,但我的观点是正确的 我接受宏或公式答案,谢谢。试试这样的答案。 在vba ide中,您必须获得工具->参考并选择 “Microsoft ActiveX数据对象2.8库” 选项显式 私有子分类器存在() 可能作为新的ADODB.Recordset Di

看这个例子:

我在第一栏有所有可能的信息,第二栏只有物理上存在的信息。从第二列开始的行显示存在的信息

有没有办法把事情弄清楚

我试过按字母顺序排序,但并没有像我演示的那样有效。还要注意,这只是一个示例。 在我的主要工作表中,事情之间并不十分接近,但我的观点是正确的

我接受宏或公式答案,谢谢。

试试这样的答案。 在vba ide中,您必须获得工具->参考并选择 “Microsoft ActiveX数据对象2.8库”

选项显式
私有子分类器存在()
可能作为新的ADODB.Recordset
Dim RSE作为新ADODB.Recordset存在
将ws设置为Excel.Worksheet
暗淡的光线和长的一样
暗淡如长
设置ws=Application.ActiveSheet
'将字段添加到记录集中以存储数据。你可以在这里存储总和。
有可能
.Fields.Append“行”,adInteger
.Fields.Append“可能”,adChar,20
打开
以
与马克思主义者
.Fields.Append“存在”,adChar,20
.Fields.Append“Value1”,adChar,30
.Fields.Append“Value2”,adChar,33'使字段尽可能大。
.Fields.Append“Value3”,adChar,20
打开
以
lRow=1
'循环并记录列中的内容。

我很确定,如果不应用宏,你就无法做到这一点,这是一个可接受的解决方案吗?@erikdaude,正如我在问题中所说:“我接受宏或公式答案,谢谢。“是的,我不知道没有VBA你怎么能在原地完成,但如果你准备在其他地方复制C列的内容并查找D:G列,你可以使用VLOOKUP或匹配/索引公式。欢迎使用!阅读能帮助你更快地得到答案。记住,这不是一个代码编写服务,所以发布你所拥有的&我们可以帮助你修复它。如果您不知道从哪里开始,请尝试使用宏录制器。@FreeMan感谢您的欢迎信息。问题是我不知道如何从代码开始,所以我想知道是否有一个公式。既然没有,我还是不知道该怎么开始。如果我有代码,我会发布我的代码。代码中有一些错误,它给了我语法错误:
.Fields.Append“可能”,adChar,20
,你忘了完成注释行
“在th
中查找当前存在的宏,我在哪里分配宏,我没有找到将其分配给按钮或任何东西的方法。@Atheisthotdog我修复了额外的引号,我的坏消息。”。要将其“分配”到按钮,只需将sub的主体放入您喜欢的按钮事件中,可能是单击事件。因此,Private Sub-SortExisting()和End Subit()之间的所有内容仍然在
.Fields.Append“可能”,adChar,20
change.Fields.Append“可能”,adChar,20到.Fields.Append“可能”,adChar,20去掉额外的”
Option Explicit

Private Sub SortExisting()
Dim rsPossible As New ADODB.Recordset
Dim rsExists As New ADODB.Recordset
Dim ws As Excel.Worksheet
Dim lRow As Long
Dim lFind as Long

    Set ws = Application.ActiveSheet

    'Add fields to your recordset for storing data.  You can store sums here.
    With rsPossible
        .Fields.Append "Row", adInteger
        .Fields.Append ""Possible", adChar, 20
        .Open
    End With

    With rsExists
        .Fields.Append "Exists", adChar, 20
        .Fields.Append "Value1", adChar, 30
        .Fields.Append "Value2", adChar, 33  'Make the fields as big as they need to be.
        .Fields.Append "Value3", adChar, 20
        .Open
    End With

    lRow = 1

    'Loop through and record what is in the columns.
    Do While lRow <= ws.UsedRange.Rows.Count

        rsPossible.AddNew
        rsPossible.Fields("Row").Value = lRow
        rsPossible.Fields("Possible").Value = ws.Range("C" & lRow).Value
        rsPossible.Update

        rsExists.AddNew
        rsExists.Fields("Exists").Value = ws.Range("D" & lRow).Value
        ws.Range("D" & lRow).Value = ""
        rsExists.Fields("Value1").Value = ws.Range("E" & lRow).Value
        ws.Range("E" & lRow).Value = ""
        rsExists.Fields("Value2").Value = ws.Range("F" & lRow).Value
        ws.Range("F" & lRow).Value = ""
        rsExists.Fields("Value3").Value = ws.Range("G" & lRow).Value
        ws.Range("G" & lRow).Value = ""
        rsExists.Update

        lRow = lRow + 1
        ws.Range("A" & lRow).Activate
    Loop

    If rsExists.EOF = False Then
        rsExists.MoveFirst
    End If

    'Here we loop through the existing
    Do While rsExists.EOF = False
        "Find the current existing in th
        rsPossible.Filter = ""
        rsPossible.Filter = "Possible='" & rsExist.fields("Exists").Value
        lFind = rsPossible.Fields("Row").Value

        'Write the value of the existing to the row of the possible
        ws.Range("D" & lFind).Value = rsPossible.Fields("Exists").Value
        ws.Range("E" & lFind).Value = rsPossible.Fields("Value1").Value
        ws.Range("F" & lFind).Value = rsPossible.Fields("Value2").Value
        ws.Range("G" & lFind).Value = rsPossible.Fields("Value3").Value

    rsExists.MoveNext
    Loop

End Sub