Range questions - Paste in order and Autofit

Sayth

Board Regular
Joined
Jun 4, 2010
Messages
212
Can I ask 2 quick questions.

I selected a range of columns and copied. When they paste into the new sheet however they don't paste in the order they were selected they paste in order of occurrence. here is my code. How can i paste as selected.

Code:
Dim WS As Worksheet
Set WS = Sheets.Add

    WS.Name = ("Report")
    ActiveCell.FormulaR1C1 = "=Table_owssvr_1[Column1]"
    Range("A1").Select
    Selection.ClearContents
    Sheets("Data").Select
    Range("O:O,P:P,S:S,R:R,E:E,F:F,G:G").Select
    Selection.Copy
    Sheets("Report").Select
    Range("A1").Select
    ActiveSheet.Paste

Second I defined a range of columns I wanted to apply autofit to but it errors. Is there a correct way to do this? this is what I did.


Code:
Columns("O:O,P:P,S:S,R:R,E:E,F:F,G:G").EntireColumn.AutoFit
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
try this see if it helps


Code:
Sub tests()
Dim WS As Worksheet
Dim i As Long, rng As Range
Set WS = Sheets.Add
WS.Name = ("Report")
Set rng = Sheets("Data").Range("O:O,P:P,S:S,R:R,E:E,F:F,G:G")
    For i = 1 To rng.Areas.Count
        Sheets("data").Range(rng.Areas(i).Address).Copy Destination:=WS.Range("a1").Offset(0, i - 1)
    Next
WS.UsedRange.EntireColumn.AutoFit
End Sub
 
Upvote 0
try this see if it helps


Code:
Sub tests()
Dim WS As Worksheet
Dim i As Long, rng As Range
Set WS = Sheets.Add
WS.Name = ("Report")
Set rng = Sheets("Data").Range("O:O,P:P,S:S,R:R,E:E,F:F,G:G")
    For i = 1 To rng.Areas.Count
        Sheets("data").Range(rng.Areas(i).Address).Copy Destination:=WS.Range("a1").Offset(0, i - 1)
    Next
WS.UsedRange.EntireColumn.AutoFit
End Sub

Is there anywhere in there I can define pasteSpecial values only as it does solve the column problem but results in #ref values.
 
Upvote 0
try this

Code:
Sub tests()
Dim WS As Worksheet
Dim i As Long, rng As Range
Set WS = Sheets.Add
WS.Name = ("Report")
Set rng = Sheets("Data").Range("O:O,P:P,S:S,R:R,E:E,F:F,G:G")
    For i = 1 To rng.Areas.Count
        
        Sheets("data").Range(rng.Areas(i).Address).Copy
        WS.Range("a1").Offset(0, i - 1).PasteSpecial Paste:=xlPasteValues
        
    Next
WS.UsedRange.EntireColumn.AutoFit
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,085
Messages
6,128,733
Members
449,465
Latest member
TAKLAM

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