excel 选择一行并转置到一个单元格中

busg9geu  于 2022-12-20  发布在  其他
关注(0)|答案(1)|浏览(150)

我有一个联系人列表,其中有多个电子邮件ID(一个或多个)的特定选择。我想建立一个宏,将首先选择行,然后转置所有电子邮件ID从分隔;这样我就可以使用邮件合并的数据。感谢您的支持。
我想建立一个宏,这将使我能够选择一行,并将所有的电子邮件ID从该行到一列,这是由分隔;。

pw9qyyiw

pw9qyyiw1#

在网上找到的。

Sub SingleCellAddress()
'Add Semicolon and combine cells in range into one selected cell, seperated by a semicolon and a space

Dim i As String
Dim lRow As Long
Dim rng As Range, drng As Range

    On Error Resume Next
    Set rng = Application.Selection
    Set rng = Application.InputBox("Select a range", "Select a range to combine into a single cell.", rng.Address, Type:=8)
    If Err.Number = 424 Then          'Handle cancel button
        Err.Clear
        Exit Sub
    End If
    
    On Error Resume Next
    Set drng = Application.InputBox("Select a cell to combine", "Select a cell to combine into single cell seperated by a Semicolon", Type:=8)
    If Err.Number = 424 Then          'Handle cancel button
        Err.Clear
        Exit Sub
    End If

For Each cl In rng
i = i & cl & "; "
Next cl
Range(drng.Address).Value = Trim(i)

End Sub

相关问题