|
-
Jan 31st, 2025, 08:06 PM
#1
Thread Starter
Junior Member
Sort compiles but won't run
I have a sort in VB.net that tries to sort two columns in Excel speadsheet. It compiles fine but won't execute. I get the error on selecting the range of the sort.
Dim myRange As Excel.Range
Dim sortstart As String
Dim sortend As String
sortstart = "E" & LastRow + 2 'E93
sortend = "F" & LastScore 'F98
myRange = xlWs.Range(sortstart, sortend)
myRange.Select() '<--- Error
myRange.Sort(Key1:=myRange.Range(sortend),
Order1:=Excel.XlSortOrder.xlDescending,
Orientation:=Excel.XlSortOrientation.xlSortColumns)
Error: System.Runtime.InteropServices.comException: Select method of range class failed
It looks like the "myRange.Select()" isn't working but the two valules that make up myRange are valid and good.
Anyone have any ideas what I'm missing? Thanks
Additionally here are the references: Imports System.Configuration
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel
Imports Excel = Microsoft.Office.Interop.Excel
Last edited by JimReid; Feb 1st, 2025 at 06:54 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|