【问题标题】:Using VBA cut cell text and format with double click then paste with next click双击使用VBA剪切单元格文本和格式,然后单击粘贴
【发布时间】:2018-07-11 00:07:39
【问题描述】:

尝试进行设置,以便双击单元格剪切文本和格式,然后单击另一个单元格粘贴剪切的文本和格式。当前代码仅将未格式化的文本粘贴到新单元格中。

这是我现在拥有的

    Option Explicit

    Dim CutValue
    Dim CutCell As Range

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

        Cancel = True
        Target.Cut 
        CutValue = Target.Text
        Set CutCell = Target

    End Sub

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

        If Not IsEmpty(CutValue) Then
            Target.FormulaR1C1 = CutValue
            CutValue = Empty
            CutCell.Clear
        End If

    End Sub

非常感谢您的帮助。

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    您可以延迟剪切,直到用户选择另一个单元格:

    Option Explicit
    
    Dim CutCell As Range
    
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    
        Cancel = True
        Set CutCell = Target
    
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        If Not CutCell Is Nothing Then
            CutCell.Cut Target.Cells(1) '<<<in case of multi-cell selection...
            Set CutCell = Nothing
        End If
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多