user3743515
user3743515

Reputation: 11

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.

Upvotes: 1

Views: 110

Answers (1)

L42
L42

Reputation: 19737

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

Upvotes: 1

Related Questions