Need some help with more effective range manipulation
Untested, but try this
Dim testrange As String
Dim SortRangeX As String
testrange = InputBox(prompt:="Enter Column Letter", Title:="Sort")
SortRangeX = testrange & ":" & testrange
Range("4:28").Copy
With Sheets("Sort")
.Range("A1").PasteSpecial Paste:=xlFormulas
.Range("A1").Sort Key1:=.Range(SortRangeX), Order1:=xlDescending
.Range("A1").Copy
End With
Sheets("Main Scorecard (All FSEs)").Range("A4").PasteSpecial
Paste:=xlFormulas
Application.CutCopyMode = False
--
HTH
Bob Phillips
(replace somewhere in email address with gmail if mailing direct)
"havocdragon" wrote in message
...
Hi all,
I see alot on here about not using select and active or the like when
editing excel code for efficiency. So I am practicing on revising some
code I
have, but I am running into a few problems.
Here is my code, my questions are below it.
Dim testrange As String
Dim SortRangeX As String
testrange = InputBox(prompt:="Enter Column Letter", Title:="Sort")
SortRangeX = testrange & ":" & testrange
Range("4:28").Copy
Sheets("Sort").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlFormulas
Application.CutCopyMode = False
Selection.Sort Key1:=Range(SortRangeX), Order1:=xlDescending
Selection.Copy
Sheets("Main Scorecard (All FSEs)").Select
Range("A4").Select
Selection.PasteSpecial Paste:=xlFormulas
Application.CutCopyMode = False
Now keep in mind, that this is copying from "Main Scorecard(All FSEs)" and
pasting to "Sort" sheet sorting and placing it back into the original
sheet.
Here are some issues I have when revising it.
I could do
Range("4:28").Copy
Sheets.("Sort").Range("A1").paste special Paste:=XlFormulas
However the focus is still on the main sheet, and I cannot figure out how
to
execute the sort on the sorting sheet without selecting it first.
Also, is there a way to get the range.copy and sheets.range.paste special
all in one line?
|