简体   繁体   English

当前选择中的VBA选择单元

[英]VBA select cell within current selection

I recorded the following to transpose a vertical set of cells to a range displaced two cells to the right from the start of the original range. 我记录了以下内容,以将一组垂直的单元格转置到从原始范围的开始向右移动两个单元格的范围内。

Sub Macro4()
'
' Macro4 Macro
'
' Keyboard Shortcut: Option+Cmd+u
'
    Range("A105:A115").Select
    Selection.Copy
    Range("C105").Select
    Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
        , Transpose:=True
    ActiveWindow.SmallScroll Down:=6
    Range("A116").Select
End Sub

Now, I want to run the macro to perform this operation relative to other manually highlighted cells. 现在,我要运行宏以相对于其他手动突出显示的单元格执行此操作。 How can I edit the code to do that? 我该如何编辑代码来做到这一点? Thanks. 谢谢。

Try this: 尝试这个:

Dim rng As Range
If TypeName(Selection) = "Range" Then 
    Set rng = Selection
    rng.Copy
    rng.Offset(0, 2).Resize(1, 1).PasteSpecial xlPasteAll, , , True
End If

HTH HTH

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM