PasteSpecial Method of Range Class Failed

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
I would like to be able to take data presented along a single row and have it moved to a single column. The code below is what I have constructed in order to accomplish this task. I am receiving an error "Pastespecial method of range class failed" on the line immediately below. Why is it doing this?

Code:
 ActiveCell.Offset(1, -1).PasteSpecial Paste:=xlPasteValues

Code:
   Dim A As Integer    Dim B As Integer


'
    ActiveCell.Activate
    
    A = ActiveCell.End(xlToRight).Column
    
    For B = 0 To A
    
        ActiveCell.Offset(0, 1).Select
    
        ActiveWorkbook.ActiveSheet.Range(ActiveCell, Cells(ActiveCell.Row, ActiveCell.End(xlToRight).Column)).Cut
    
        ActiveCell.Offset(1, -1).PasteSpecial Paste:=xlPasteValues
        
        ActiveCell.Activate
    
    Next B
    
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try this code:

Code:
Public Sub DoIt()
    With ActiveSheet.Range(ActiveCell, ActiveCell.End(xlToRight))
        .Copy
        .Offset(1, -1).Resize(, 1).PasteSpecial Transpose:=True
        .ClearContents
    End With
End Sub


  • It first selects the range in the row (starting from the active cell, to the last column with data - note that if you have blank cells in between, then it will not work right).
  • With ... End With helps to work with the same object reference in this sample.
  • It then copies the range, runs PasteSpecial on the one row below of the previous column with Transpose option, so it pastes row range as column. We don't want to use Cut method but Copy because we need to use PasteSpecial.
  • Then while we are still in With ... End With, ClearContents clears the original source range (Cut effect).

We just need the ActiveCell object to define the starting point in this code, then we use Offset and Resize methods to define the source and target ranges instead activating and processing each cell.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,686
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top