Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 49892

[SOLVED] Setting dynamic range producing error 13

$
0
0
Hello experts. I am looking for a little clarity. I'm curious why an error 13 is thrown when setting the range.
Code:

    Dim s As String: s = "temp"
    Dim rng As Range
   
    Set wb = ThisWorkbook
    Set ws = wb.Sheets(s)
        With ws
            lrow = LastRow(ws) 'call function c. of de Bruin
            ColNo = LastCol(ws) 'call function c. of de Bruin
            ColLetter = Split(Cells(1, ColNo).Address, "$")(1)
            Set rng = .Range("A1:" & ColLetter & lrow) 'vba allows a step through this
            MsgBox rng.Address
            Range(rng).sort key1:=Range("A1:A" & lrow), order1:=xlAscending, Header:=xlYes 'error 13 here....
        End With

EDIT: MsgBox rng.Address says the range is set...I guess what the meat issue is the sort is not recognizing the declared range

Viewing all articles
Browse latest Browse all 49892

Trending Articles