[英]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.