Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello:

The following procedure is supposed to iterate through my worksheets, delete the first 7 rows and then delete all columns where the names do not match those below.

The first part of my code works fine, it deletes the first 7 rows. However, when it gets to this line:

Select Case LCase(.UsedRange.Cells(1, i))


I get the following error:

System.Reflection.AmbiguousMatchException was unhandled by user code
  Message=Overload resolution failed because no Public 'LCase' can be called with these arguments:
    'Public Shared Function LCase(Value As Char) As Char':
        Argument matching parameter 'Value' cannot convert from '__ComObject' to 'Char'.
    'Public Shared Function LCase(Value As String) As String':
        Argument matching parameter 'Value' cannot convert from '__ComObject' to 'String'.


I can't quite figure out what I am doing wrong here. The whole procedure is as follows:

Dim xlWB As Excel.Workbook = CType(Globals.ThisWorkbook.Application.ActiveWorkbook, Excel.Workbook)
Dim xlWSPosition As Excel.Worksheet = CType(CType(xlWB.Sheets("byPosition"), Excel.Worksheet), Excel.Worksheet)
Dim xlWSEmployee As Excel.Worksheet = CType(CType(xlWB.Sheets("byEmployee"), Excel.Worksheet), Excel.Worksheet)

Dim xlSheets As Object
Dim xlSheetsArray(0 To 1) As Excel.Worksheet
Dim k As Long
Dim i As Long

    xlSheetsArray(0) = xlWSPosition
    xlSheetsArray(1) = xlWSEmployee

    For Each xlSheets In xlSheetsArray

        With xlSheets

            'With the above sheets, replace the first 7 rows. They only contain Payscale generic information so we can get rid of it.
            .Rows("1:7").Delete(Excel.XlInsertShiftDirection.xlShiftDown)


            k = .UsedRange.Columns.Count

            'For the referenced sheets above delete all columns except for the ones liste below.  These columns the reference column for the entire workbook.

            For i = k To 1 Step -1
                Select Case LCase(.UsedRange.Cells(1, i))
                    Case "#ees", "annu. base at target", "annualized fte base pay", "annu. base mkt - 10th" 


                        'do nothing
                    Case Else
                        .UsedRange.Columns(i).Delete()
                End Select
            Next i
        End With

    Next xlSheets

End Sub
Posted
Updated 11-Sep-13 16:13pm
v2

1 solution

You are trying to pass an object to a function that is expecting a string. Try

lcase(.usedrange.cells(1, i).value)


or similar.
 
Share this answer
 
Comments
qbndl8 11-Sep-13 22:38pm    
I knew it was something simple. I just started working on VB.Net, my experience is on VBA so I am still getting used to the little nuances.

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900