excel vba - VBA .Sort feature for List Box -


i've used exact same vba code before on other listboxes add non-duplicates quite successfully. unfortunately, time it's giving me error "application-defined or object-defined error." insights on appreciated, i'm not sure why it's not adding items list. activex listbox well, being added on worksheet instead of user form. i've done exact same code before without problems, time errors out at: rngdata.sort

private sub lstcountry_click() dim wsdata worksheet dim strid string dim rngdata range dim rngcell range dim shtpivot set shtpivot = thisworkbook.worksheets("pivot") set wsdata = thisworkbook.worksheets("raw data") set rngdata = wsdata.range("a2").currentregion   lstcountry.clear strid = "select country" rngdata.sort key1:=strid, header:=xlyes   each rngcell in rngdata.columns(1).cells     if rngcell.value <> strid         lstcountry.additem rngcell.value         strid = rngcell.value     end if next rngcell 

attached screenshot of table i'm trying sort enter image description here

here example how use sort option: https://msdn.microsoft.com/en-us/library/office/ff840646.aspx

in case, not have "select country" written on top of range. top range row 2. can give screenshot?


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -