I made some codes below, is to past with link and transpose in worksheet. But when I run second procedure('WT_Transpose'), an error occured: Object variable not set (Error 91).
If you run each procedure in order in the editor it worked normally. But why can't recognize the rngMulti object when I run it using shortcut keys in the worksheet? Is there any way to share assigned variables between procedures?
Option Explicit
Dim rngMulti As Range
Private Sub Ctrl_Copy()
'Shortcut: Ctrl+c
On Error GoTo Err_Step
Selection.Copy
Set rngMulti = Selection
Err_Step:
End Sub
Private Sub WL_Transpose()
'Shortcut: Alt+Shift+v
Dim r, c As Long
Dim xr, xc As Long
Dim i, j As Long
Dim text As String
Dim xcell As Range
r = rngMulti.Rows.Count
c = rngMulti.Columns.Count
xr = c
xc = r
ReDim arr(1 To xr, 1 To xc)
For xr = 1 To c
For xc = 1 To r
arr(xr, xc) = Split(rngMulti.Cells(xc, xr).Address(external:=True), "]")(1)
Next xc
Next xr
ActiveCell.Resize(xr - 1, xc - 1).Value = arr
ActiveCell.Resize(xr - 1, xc - 1).Select
For Each xcell In Selection
xcell.Formula = "='" & xcell.Formula
Next xcell
End Sub