Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Sort a dynamic Range in Excel with Powershell

$
0
0

So, i've done a lot of searching and i've come up empty...


I use a lot of excel within powershell, but i've never done dynamic sorting.

Here's the snippet from the macro.

"    Rows("1:582").Select
    ActiveWorkbook.Worksheets("Filer").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Filer").Sort.SortFields.Add Key:=Range("A2:A582") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Filer").Sort
        .SetRange Range("A1:AK582")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply

"

 

I'm having trouble turning that into powershell at all.. 

 

I usually do dynamic range building with stuff like -

    $cells = ("A" + $ydx + ":" + "D" + $ydx)
    $Range = $filersheet.range("$cells")
    ## Merge Cells
    $Range.merge() | Out-Null

But in this example, I need to stop before I do that merged cell and then sort only above that..

I don't think i will have a hard time identifying dynamic range, it's more of how to sort via excel.

 

Any guidance would be great


Viewing all articles
Browse latest Browse all 6937

Trending Articles