LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Type mismatch in vlookup


Hello all, I'm having a hard time trying to figure this one out. All
this code does is look at column F in a report, take the value from the
cell in the active row, and assign it to "Sku". It then checks to see
if a sheet named divcodes is open, if not, it'll open it. From there
it does a vlookup in divcodes and returns the code corresponding to
"Sku". If there's no code, it returns "??".

It was working just fine a few days ago, and now I get a type mismatch
at the vlookup line. From the searching I did in the forums I'm
suspecting its how I assigned the range to dCodePath, but I'm not sure
how I'd fix that. Sku comes back as a string, and I removed CStr()
thinking that may be it, but no dice. Can anybody point me in the
right direction? I'd highly appreciate it:)


Code:
--------------------

Sub DivisionCode(dCode)
'Selects division code for part numbers from external sheet

Dim Sku, dCodePath, Check As Boolean
Dim wb As Workbook, wSht As Worksheet

Application.DisplayAlerts = False

origWB = ActiveWorkbook.Name
Sku = Cells(ActiveCell.Row, 6).Value

'Checks if DivCodes sheet is open
For Each wb In Workbooks

If wb.Name < ThisWorkbook.Name Then
For Each wSht In wb.Worksheets
If wSht.Name = "All skus" Then
Check = True
End If
Next wSht
End If

Next wb

Set wb = Nothing
Set wSht = Nothing

If Check = True Then
dCodePath = Workbooks("Divcodes.xls").Worksheets(1).Range("A2: B11243")
Else
With Application.Workbooks.Open("C:\Documents and Settings\My Documents\Excel\Divcodes.xls")
.Application.ActiveWindow.Visible = False
End With
dCodePath = Workbooks("Divcodes.xls").Worksheets(1).Range("A2: B11243")
End If

Workbooks(origWB).Activate
dCode = Application.VLookup(CStr(Sku), dCodePath, 2, 0)

'Error handling
If IsError(dCode) Then
Workbooks(origWB).Sheets(1).Activate
dCode = "??"
End If

End Sub

--------------------


--
carg1
------------------------------------------------------------------------
carg1's Profile: http://www.excelforum.com/member.php...o&userid=15271
View this thread: http://www.excelforum.com/showthread...hreadid=530644

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type mismatch using rnge as Range with Type 8 Input Box STEVE BELL Excel Programming 11 December 3rd 05 05:02 AM
Type mismatch ! Roshintosh Excel Programming 7 November 10th 05 07:13 PM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Type Mismatch in Vlookup? LJones[_2_] Excel Programming 1 August 5th 04 07:30 AM
Type Mismatch Phil Hageman[_3_] Excel Programming 2 January 9th 04 06:11 PM


All times are GMT +1. The time now is 04:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"