Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Type Mismatch Problem

I am trying to debug the following line of code and am not sure why I am
getting an error as everything looks fine to me. The line is:

If IsError(Application.VLookup(Cells(ProductTitleRow, j),
Workbooks(Current_Consolidated_Units).Sheets(Cells (i,
RegionColumn)).Range("L410:BC418"), Consolidated_Offset + Growth * Cells(i,
GrowthColumn), False)) Then

And the values which come up as I move my mouse over each item a
Cells(ProductTitleRow, j)="APPL/PROF SVC"
Current_Consolidated_Units="2006 Access Based Units - Actuals.xls"
Cells(i, RegionColumn)="QC"
Consolidated_Offset=36
Growth=6
Cells(i, GrowthColumn)=1

I am at a loss in understanding what might be wrong as it looks to me as
though all types within all fields are correct. Can you tell me if you see a
problem. Or is there something else that might be wrong?

Thanks.

Darrell
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Type Mismatch Problem

I have noticed that when I type in "QC" in place of Cells(i, RegionColumn)
that I get no error. How can this happen? It does not make any sense.

Darrell

"DarrellK" wrote:

I am trying to debug the following line of code and am not sure why I am
getting an error as everything looks fine to me. The line is:

If IsError(Application.VLookup(Cells(ProductTitleRow, j),
Workbooks(Current_Consolidated_Units).Sheets(Cells (i,
RegionColumn)).Range("L410:BC418"), Consolidated_Offset + Growth * Cells(i,
GrowthColumn), False)) Then

And the values which come up as I move my mouse over each item a
Cells(ProductTitleRow, j)="APPL/PROF SVC"
Current_Consolidated_Units="2006 Access Based Units - Actuals.xls"
Cells(i, RegionColumn)="QC"
Consolidated_Offset=36
Growth=6
Cells(i, GrowthColumn)=1

I am at a loss in understanding what might be wrong as it looks to me as
though all types within all fields are correct. Can you tell me if you see a
problem. Or is there something else that might be wrong?

Thanks.

Darrell

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Type Mismatch Problem

Are you using xl2007? If so "QC" could be interpreted as a column designation.
Is the same sheet active every time the code is run?
You are telling Excel to read the sheet name from the active sheet...
I would qualify every "Cells" with the appropriate workbook/worksheet.
That may or may not help, but it is correct practice.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"DarrellK"
wrote in message
I have noticed that when I type in "QC" in place of Cells(i, RegionColumn)
that I get no error. How can this happen? It does not make any sense.
Darrell

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Type Mismatch Problem

There are two things that would scare me--but shouldn't cause trouble if you're
lucky <vbg.

The first is that that formula is too complex to make it easy to debug (my
problem, not yours). The second problem(s) are the unqualified ranges in that
code.

Cells(producttitlerow,j)
will refer to the activesheet or the sheet that owns the code (if the code is in
a worksheet module).

I'd be more explicit:

Dim MyLookupVal As Variant
Dim mySheetName as string
dim myLookupRng as range
dim myGrowthOffset as Variant
dim res as variant

with thisworkbook.worksheets("sheet9999") 'or with me, or with activesheet
mylookupval = .cells(producttitlerow, j).value
mysheetname = .cells(i, RegionColumn).value
myGrowthOffset = .cells(i, growthcolumn).value

if isnumeric(mygrowthoffset) then
'ok
else
msgbox .cells(i, growthcolumn).address & " doesn't contain a number!"
exit sub
end if
end with

set mylookuprng = nothing
on error resume next
set mylookuprng = Workbooks(Current_Consolidated_Units) _
.worksheets(mysheetname).range(L410:bc418")
on error goto 0

if mylookuprng is nothing then
msgbox "Error with lookup range--check sheet name or workbook name!"
exit sub
end if

res = application.vlookup(mylookupval, mylookuprng, _
Consolidated_Offset + (Growth * myGrowthOffset), false)

'the ()'s around the growth*mygrowthoffset aren't required--I just like them!

if iserror(res) then
msgbox "not found"
else
msgbox "Found it and it's = " & res
end if

=========
But this doesn't explain why it didn't work--but it may help you debug it.

Good luck.

DarrellK wrote:

I have noticed that when I type in "QC" in place of Cells(i, RegionColumn)
that I get no error. How can this happen? It does not make any sense.

Darrell

"DarrellK" wrote:

I am trying to debug the following line of code and am not sure why I am
getting an error as everything looks fine to me. The line is:

If IsError(Application.VLookup(Cells(ProductTitleRow, j),
Workbooks(Current_Consolidated_Units).Sheets(Cells (i,
RegionColumn)).Range("L410:BC418"), Consolidated_Offset + Growth * Cells(i,
GrowthColumn), False)) Then

And the values which come up as I move my mouse over each item a
Cells(ProductTitleRow, j)="APPL/PROF SVC"
Current_Consolidated_Units="2006 Access Based Units - Actuals.xls"
Cells(i, RegionColumn)="QC"
Consolidated_Offset=36
Growth=6
Cells(i, GrowthColumn)=1

I am at a loss in understanding what might be wrong as it looks to me as
though all types within all fields are correct. Can you tell me if you see a
problem. Or is there something else that might be wrong?

Thanks.

Darrell


--

Dave Peterson
Reply
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 problem... Trevor Williams Excel Programming 3 February 5th 07 05:50 PM
Type mismatch problem Dan Excel Programming 7 May 31st 06 04:55 PM
Type mismatch problem in array - ?? ina Excel Programming 6 May 17th 06 12:56 PM
Type Mismatch Problem Damien McBain[_2_] Excel Programming 2 May 20th 05 04:09 PM
Type mismatch problem? NooK[_45_] Excel Programming 3 August 4th 04 01:07 PM


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

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

About Us

"It's about Microsoft Excel"