Copy Excel data from columns to rows with VBA

后端 未结 6 1069
梦如初夏
梦如初夏 2021-01-21 20:16

I have a little experience with VBA, and I would really appreciate any help with this issue. In a basic sense, I need to convert 2 columns of data in sheet 1 to rows of data in

6条回答
  •  有刺的猬
    2021-01-21 20:42

        'The following code is working OK
        Sub TansposeRange()
        '
        ' Transpose Macro
        '
        Dim wSht1 As Worksheet
        Dim rng1 As Range
        Dim straddress As String
        Set wSht1 = ActiveSheet
    
        On Error Resume Next
        Set rng1 = Application.InputBox(Prompt:="Select Columns or Rows to transpose", _
                                       Title:="TRANSPOSE", Type:=8)
        If rng1 Is Nothing Then
            MsgBox ("User cancelled!")
            Exit Sub
        End If
        straddress = InputBox(Prompt:="Full cell Address as Sheet2!A1", _
              Title:="ENTER Full Address", Default:="Sheet1!A1")
        If straddress = vbNullString Then
             MsgBox ("User cancelled!")
             Exit Sub
        End If      
    
        Application.ScreenUpdating = False
        rng1.Select
        rng1.Copy
    
        On Error GoTo 0
    
        'MsgBox straddress
        Range(straddress).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
        Application.ScreenUpdating = True
        End Sub
    

提交回复
热议问题