简体   繁体   English

如果另一列等于值,将单元格从一列复制到剪贴板的宏

[英]Macro to Copy Cells from one Column to the Clipboard if Another Column Equals Value

I have a large list of contacts and I want a macro that copies their email addresses, Column J, to the clipboard if they've been selected, ="a" in Column C. 我有大量的联系人,我想要一个宏,如果将其电子邮件地址(列J)复制到剪贴板,则将其复制到剪贴板(列C中的=“ a”)。

The contact list is constantly edited with some being deleted and others added. 联系人列表不断进行编辑,其中一些被删除,而另一些则被添加。 I've named the row above and below the data information for function reference which has been working well with my other macros. 我将数据信息的上方和下方的行命名为函数引用,该行与我的其他宏配合得很好。

Sub CopySelected()
Dim oData As New DataObject 
oData.SetText Text:=Empty 'Clear
oData.PutInClipboard
With Worksheets("Master")
    For Each Cell In Range(.Cells(.Range("BorderFirstRow").Row + 1, "C"), _
                .Cells(.Range("BorderLastRow").Row - 1, "C"))
        If Cell.Value = "a" Then

                .PutInClipboard
        End If
    End With
End Sub

What do I need to do to have the macro copy the email address, Column J, if Column C="A"? 如果列C =“ A”,宏需要如何复制电子邮件地址列J?

This is a fictitious worksheet with fictitious data. 这是一个包含虚拟数据的虚拟工作表。 Hope it is like yours: 希望它像你一样: 在此处输入图片说明 The code below gave no errors for me: 下面的代码对我来说没有错误:

Sub CopyToClip()

Dim ClipB As New DataObject
Dim RangeToConsider As Range
Dim strAddresses As String

    ' set the range
    ' here just set the relevant range from the C column
        Set RangeToConsider = Range("E4:E7") ' in my case!
For Each cell In RangeToConsider
    If cell.Value = "a" Or cell.Value = "A" Then
        If Not (Trim(cell.Offset(0, -2).Value) = "") Then
           strAddresses = strAddresses & "; " & cell.Offset(0, -2).Value
        end if
    End If
Next
strAddresses = Mid(strAddresses, 2) ' delete the first semicolon
strAddresses = strAddresses & ";" ' add a semicolon at the end
strAddresses = Trim(strAddresses) ' delete spaces if any
Debug.Print strAddresses
ClipB.SetText strAddresses
ClipB.PutInClipboard
Debug.Print ClipB.GetText()
End Sub

So, after running the procedure, I am able to paste 'Name; 因此,运行该过程后,我可以粘贴“名称; AnotherName;' AnotherName;”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果一个单元格等于条件,则查找范围内的单元格将其值复制到另一列 - Find cells within a range if one cell equals a criteria copy its value to another column 将多个单元格从excel列复制到剪贴板 - Copy multiple cells from excel column to clipboard Excel宏-根据值将单元格从一张纸复制到另一张纸 - Excel Macro - copy cells from one sheet into another based on value 从一列中的一行复制一个单元格,具体取决于另一列中相应行中的值 - Copy cells from one a row in a column dependant on a value in the corresponding row in another column Excel宏/方法从一列复制到另一列 - excel macro/methid to copy from one column to another 从一张纸到另一张纸的VBA宏复制列,中间有空白 - VBA macro copy column from one sheet to another with blanks in between 将某个字符串从excel单元格中的一列复制到另一列 - Copy a certain string from excel cells in one column to another 如果单元格的值等于另一列的任何值,则有条件地格式化单元格 - Conditionally formatting cells if their value equals any value of another column 条件格式化单元格,如果它们的一部分值等于另一列的ANY值 - Conditional formatting cells if part of their value equals ANY value of another column 根据另一列中的条件将一列中的单元格复制到另一张工作表 - Copy Cells in One Column, Based on Criteria in Another Column, to Another Sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM