Force “F2”+“Enter” on range of cells

后端 未结 12 1827
伪装坚强ぢ
伪装坚强ぢ 2021-01-04 05:31

I have an Excel 2010 worksheet which has macros to copy data from other sheets into a specific format on another sheet.

The data copies but I have an issue with the

12条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-04 05:44

    Sendkeys are not stable. The better way is to store the text in the clipboard and paste it.

    See here on how to store values in the clipboard

    Sub CopyText(Text As String)
    Dim MSForms_DataObject As Object
    Set MSForms_DataObject = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    MSForms_DataObject.SetText Text
    MSForms_DataObject.PutInClipboard
    Set MSForms_DataObject = Nothing
    End Sub
    
    Sub Test()
    CopyText (ActiveCell.Value)
    ActiveCell.PasteSpecial
    End Sub
    'In place of active cell, you may pass a range
    

提交回复
热议问题