What is wrong here with code

Andries

Board Regular
Joined
Feb 3, 2011
Messages
127
Hi All

Please explain and/or correct this code.

I am trying to paste the formula that is in Sheets("data2").Range("DT2:EG3272").

Code:
Sheets("data2").Range("DT2:EG3272").Copy Destination:=.Range("DT2").Select.PasteSpecial = xlPasteFormulas[code]
 
I thank you
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try:

Code:
Sheets("data2").Range("DT2:EG3272").Copy
.Range("DT2").PasteSpecial = xlPasteFormulas

The code needs to be inside a With ... End With construct for a worksheet (because of the dot before Range).
 
Upvote 0
Andrew

How can I make this code shorter and the code must run on the active sheet and not on a specific sheet like in this code below.

Code:
Range("CZ1:DS3271").Select
    ActiveWorkbook.Worksheets("13").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("13").Sort.SortFields.Add Key:=Range("CZ2:CZ3271") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("13").Sort
        .SetRange Range("CZ1:DS3271")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub[code]
 
Upvote 0
Like this?

Code:
    With ActiveSheet.Sort
        .SortFields.Clear
        .SortFields.Add Key:=Range("CZ2:CZ3271") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        .SetRange Range("CZ1:DS3271")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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