Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.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 搜索特定的列标题名称,复制列并粘贴以附加到另一个wookbooksheet_Excel_Excel 2010_Vba - Fatal编程技术网

Excel 搜索特定的列标题名称,复制列并粘贴以附加到另一个wookbooksheet

Excel 搜索特定的列标题名称,复制列并粘贴以附加到另一个wookbooksheet,excel,excel-2010,vba,Excel,Excel 2010,Vba,我的工作簿有一张、两张或三张。 每张表至少可以包含一个列标题名:Tel或Number 如何仅使用这些列标题名称复制整个列数据 并将它们作为附加项粘贴到另一个工作簿工作表中,其中包含VBA代码工作表模块,该工作簿工作表只包含一个具有相同列标题名称的列。谢谢 到目前为止你所做的一切都会很有帮助。到目前为止你所做的一切都会很有帮助。对不起,拉里和金奇,但都不管用。错误出现在我身上。请告诉我你的名字和名字。我用我的名字替换了这个名字,在导入工作簿中用我的名字创建了一个工作表,更改了ws-set等等。如果

我的工作簿有一张、两张或三张。 每张表至少可以包含一个列标题名:Tel或Number

如何仅使用这些列标题名称复制整个列数据
并将它们作为附加项粘贴到另一个工作簿工作表中,其中包含VBA代码工作表模块,该工作簿工作表只包含一个具有相同列标题名称的列。谢谢

到目前为止你所做的一切都会很有帮助。到目前为止你所做的一切都会很有帮助。对不起,拉里和金奇,但都不管用。错误出现在我身上。请告诉我你的名字和名字。我用我的名字替换了这个名字,在导入工作簿中用我的名字创建了一个工作表,更改了ws-set等等。如果您能修复这个错误,我将不胜感激。谢谢。@user2127061将代码放入工作表模块,例如,目标工作表是工作表1,然后将代码放入工作表1的代码模块。您好,@Larry。现在它起作用了。问题是我把代码放在哪里。尽管列标题名和数字未被捕获。然后我用电话代替号码。你能修改一下吗?@user2127061你能澄清一下问题吗?您的意思是要将在number或tel中找到的所有数据添加到同一列中吗?如果这个代码解决了你原来的问题,你可能会接受它。嗨,@Larry。确切地我使用替换方法将所有数字列转换为Tel,效果很好。对不起,@Larry和kimtch,但不起作用。错误出现在我身上。请告诉我你的名字和名字。我用我的名字替换了这个名字,在导入工作簿中用我的名字创建了一个工作表,更改了ws-set等等。如果您能修复这个错误,我将不胜感激。谢谢。@user2127061将代码放入工作表模块,例如,目标工作表是工作表1,然后将代码放入工作表1的代码模块。您好,@Larry。现在它起作用了。问题是我把代码放在哪里。尽管列标题名和数字未被捕获。然后我用电话代替号码。你能修改一下吗?@user2127061你能澄清一下问题吗?您的意思是要将在number或tel中找到的所有数据添加到同一列中吗?如果这个代码解决了你原来的问题,你可能会接受它。嗨,@Larry。确切地我使用Replace方法将所有数字列转换为Tel,效果很好。
Option Compare Text

Sub search_and_append()

    Dim i As Long
    Dim width As Long
    Dim ws As Worksheet
    Dim telList As Object
    Dim count As Long
    Dim numList As Object
    Set telList = CreateObject("Scripting.Dictionary")
    Set numList = CreateObject("Scripting.Dictionary")


    ' search for all tel/number list on other sheets
    ' Assuming header means Row 1
    For Each ws In Worksheets
        If ws.Name <> Me.Name Then
            With ws
                .Activate
                width = .Cells(1, .Columns.count).End(xlToLeft).Column
                For i = 1 To width
                    If Trim(.Cells(1, i).Value) = "Tel" Then
                        Height = .Cells(.Rows.count, i).End(xlUp).Row
                        If Height > 1 Then
                            For j = 2 To Height
                                If Not telList.exists(.Cells(j, i).Value) Then
                                    telList.Add .Cells(j, i).Value, ""
                                End If
                            Next j
                        End If
                    End If
                    If Trim(.Cells(1, i).Value) = "Number" Then
                        Height = .Cells(.Rows.count, i).End(xlUp).Row
                        If Height > 1 Then
                            For j = 2 To Height
                                If Not numList.exists(.Cells(j, i).Value) Then
                                    numList.Add .Cells(j, i).Value, ""
                                End If
                            Next j
                        End If
                    End If
                Next
            End With
        End If

    Next

    ' paste the tel/number list found back to this sheet
    With Me
        .Activate
        width = .Cells(1, .Columns.count).End(xlToLeft).Column
        For i = 1 To width
            If Trim(.Cells(1, i).Value) = "Tel" Then
                Height = .Cells(.Rows.count, i).End(xlUp).Row
                count = 0
                For Each tel In telList
                    count = count + 1
                    .Cells(Height + count, i).Value = tel
                Next
            End If
            If Trim(.Cells(1, i).Value) = "Number" Then
                Height = .Cells(.Rows.count, i).End(xlUp).Row
                count = 0
                For Each tel In telList
                    count = count + 1
                    .Cells(Height + count, i).Value = tel
                Next
            End If
        Next
    End With

End Sub