In the code block I am hitting an error on the [red]red line[/red]. The error is... Error 13 Type mismatch.
This is part of a much wider range of code that is looping through all the sheets in a workbook. It always fails on the second sheet... I have swapped positions of sheets to verify it is not sheet specific. And in both cases it gets past the first sheet.
Values in use when that line blows up...
RS!Detail_Column = 2
RS!Has_Header_Row = True
This code is inside a With Excel.Application block.
So how is the sheet specified since that seems causal?
Noteworthy is that this procedure listed here is iteratively called by an outer looping procedure that opens and saves the workbook with changes to the sheet but should have little to do with the error.
Just dumbfounded on this one so any ideas?
Even making Excel visible I don't spot anything, the appropriate range IS selected. I could even manually sort the contents in debug mode.
This is part of a much wider range of code that is looping through all the sheets in a workbook. It always fails on the second sheet... I have swapped positions of sheets to verify it is not sheet specific. And in both cases it gets past the first sheet.
Values in use when that line blows up...
RS!Detail_Column = 2
RS!Has_Header_Row = True
This code is inside a With Excel.Application block.
Code:
'Delete rows that do not have required detail data
If Nz(RS!Detail_Column, 0) > 0 Then
RngFix.Parent.Activate
RngFix.Cells.Select
.Selection.Sort Key1:=RngFix.Cells(1, RS!Detail_Column), Order1:=xlAscending, Header:=IIf(RS!Has_Header_Row, xlYes, xlNo), _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
RngFix.Cells(1, RS!Detail_Column).Select
.Selection.End(xlDown).Select
.Rows(.Selection.Row + 1).Select
.Range(.Selection, .Selection.End(xlDown)).Select
.Selection.Delete Shift:=xlUp
'Sort Descending in case Text needs to be at top
RngFix.Cells.Select 'Select all
[red].Selection.Sort Key1:=.Cells(1, RS!Detail_Column), Order1:=xlDescending, Header:=IIf(RS!Has_Header_Row, xlYes, xlNo), _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal[/red]
End If
So how is the sheet specified since that seems causal?
Code:
[b].Sheets(lngSheet_Index).Select[/b]
.Sheets(lngSheet_Index).AutoFilterMode = False 'Apparently this can cause the delete blank rows section to blow up if it exists
strSheetName = .Sheets(lngSheet_Index).Name
If Nz(RS!NamedRange, "") <> "" Then
Set RngFix = .ActiveSheet.Range(RS!NamedRange) 'Named Range
Else
'Set RngFix = .ActiveSheet.Cells 'Entire Sheet
[b]Set RngFix = .Range(.ActiveSheet.Cells(1, 1), .ActiveSheet.Cells(1, 1).SpecialCells(xlLastCell))[/b] 'Work only with data on sheet
End If
Noteworthy is that this procedure listed here is iteratively called by an outer looping procedure that opens and saves the workbook with changes to the sheet but should have little to do with the error.
Just dumbfounded on this one so any ideas?
Even making Excel visible I don't spot anything, the appropriate range IS selected. I could even manually sort the contents in debug mode.