Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Run time error 13, type mismatch


Dim days As Variant
Dim hours As Variant
Dim holOptElig As Variant
Dim wb As Workbook
Set wb = Workbooks("Salary and Hourly Summary 2009.xls")
days = wb.Names("MikeNbrHolidays").Value
hours = wb.Names("MikeTotalHolHours").Value
If days 0 Then
holOptElig = hours / days <== error on this statement
End If

In "Salary and Hourly Summary 2009.xls", MikeNbrHolidays and
MikeTotalHolHours are formatted as number/0 decimal places and
number/1 decimal places respectively, and their values are 8 and
43.2. I get run time error 13, type mismatch when I run this code.

TIA,

Phil

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Run time error 13, type mismatch

I think I'd try this

holOptElig = val(hours) / val(days)

The value may not be numeric for some reason.
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"cellist" wrote:


Dim days As Variant
Dim hours As Variant
Dim holOptElig As Variant
Dim wb As Workbook
Set wb = Workbooks("Salary and Hourly Summary 2009.xls")
days = wb.Names("MikeNbrHolidays").Value
hours = wb.Names("MikeTotalHolHours").Value
If days 0 Then
holOptElig = hours / days <== error on this statement
End If

In "Salary and Hourly Summary 2009.xls", MikeNbrHolidays and
MikeTotalHolHours are formatted as number/0 decimal places and
number/1 decimal places respectively, and their values are 8 and
43.2. I get run time error 13, type mismatch when I run this code.

TIA,

Phil

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Run time error 13, type mismatch

Barb, thanks for your reply. Always a good practice to check for valid data,
but in this case it was a differentl problem.

"Barb Reinhardt" wrote:

I think I'd try this

holOptElig = val(hours) / val(days)

The value may not be numeric for some reason.
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"cellist" wrote:


Dim days As Variant
Dim hours As Variant
Dim holOptElig As Variant
Dim wb As Workbook
Set wb = Workbooks("Salary and Hourly Summary 2009.xls")
days = wb.Names("MikeNbrHolidays").Value
hours = wb.Names("MikeTotalHolHours").Value
If days 0 Then
holOptElig = hours / days <== error on this statement
End If

In "Salary and Hourly Summary 2009.xls", MikeNbrHolidays and
MikeTotalHolHours are formatted as number/0 decimal places and
number/1 decimal places respectively, and their values are 8 and
43.2. I get run time error 13, type mismatch when I run this code.

TIA,

Phil

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Run time error 13, type mismatch

Hi,

The syntax your using is returning the address of the named range try this
instead

Dim days As Variant
Dim hours As Variant
Dim holOptElig As Variant
Dim wb As Workbook
Set wb = Workbooks("Salary and Hourly Summary 2009.xls")
days = wb.Names("MikeNbrHolidays").RefersToRange
hrs = wb.Names("MikeTotalHolHours").RefersToRange
If days 0 Then

holOptElig = hrs / days '<== error on this statement
End If

Mike

"cellist" wrote:


Dim days As Variant
Dim hours As Variant
Dim holOptElig As Variant
Dim wb As Workbook
Set wb = Workbooks("Salary and Hourly Summary 2009.xls")
days = wb.Names("MikeNbrHolidays").Value
hours = wb.Names("MikeTotalHolHours").Value
If days 0 Then
holOptElig = hours / days <== error on this statement
End If

In "Salary and Hourly Summary 2009.xls", MikeNbrHolidays and
MikeTotalHolHours are formatted as number/0 decimal places and
number/1 decimal places respectively, and their values are 8 and
43.2. I get run time error 13, type mismatch when I run this code.

TIA,

Phil

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Run time error 13, type mismatch

Thanks Mike, that fixed it. deja vu to my C programming days. You know, does
the variable hold the value I want or is it a pointer to the value I want.

"Mike H" wrote:

Hi,

The syntax your using is returning the address of the named range try this
instead

Dim days As Variant
Dim hours As Variant
Dim holOptElig As Variant
Dim wb As Workbook
Set wb = Workbooks("Salary and Hourly Summary 2009.xls")
days = wb.Names("MikeNbrHolidays").RefersToRange
hrs = wb.Names("MikeTotalHolHours").RefersToRange
If days 0 Then

holOptElig = hrs / days '<== error on this statement
End If

Mike

"cellist" wrote:


Dim days As Variant
Dim hours As Variant
Dim holOptElig As Variant
Dim wb As Workbook
Set wb = Workbooks("Salary and Hourly Summary 2009.xls")
days = wb.Names("MikeNbrHolidays").Value
hours = wb.Names("MikeTotalHolHours").Value
If days 0 Then
holOptElig = hours / days <== error on this statement
End If

In "Salary and Hourly Summary 2009.xls", MikeNbrHolidays and
MikeTotalHolHours are formatted as number/0 decimal places and
number/1 decimal places respectively, and their values are 8 and
43.2. I get run time error 13, type mismatch when I run this code.

TIA,

Phil



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Run time error 13, type mismatch

I'd check both those variables.

dim OkToCalc as boolean

OkToCalc = true
if isnumeric(hours) = false then
msgbox "hours not numeric"
oktocalc = false
end if
if isnumeric(days) = false then
msgbox "days not numeric"
oktocalc = false
else
if days = 0 then
msgbox "Days is 0--division by 0 not possible"
oktocalc = false
end if
end if

if oktocalc then
holOptElig = hours / days
else
'what should happen here?
end if

cellist wrote:


Dim days As Variant
Dim hours As Variant
Dim holOptElig As Variant
Dim wb As Workbook
Set wb = Workbooks("Salary and Hourly Summary 2009.xls")
days = wb.Names("MikeNbrHolidays").Value
hours = wb.Names("MikeTotalHolHours").Value
If days 0 Then
holOptElig = hours / days <== error on this statement
End If

In "Salary and Hourly Summary 2009.xls", MikeNbrHolidays and
MikeTotalHolHours are formatted as number/0 decimal places and
number/1 decimal places respectively, and their values are 8 and
43.2. I get run time error 13, type mismatch when I run this code.

TIA,

Phil


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Run time error 13, type mismatch

Dave, thanks for your reply. Turns out it was a different kind of problem in
this case, but your suggestion is right on as a defensive programming device.

"Dave Peterson" wrote:

I'd check both those variables.

dim OkToCalc as boolean

OkToCalc = true
if isnumeric(hours) = false then
msgbox "hours not numeric"
oktocalc = false
end if
if isnumeric(days) = false then
msgbox "days not numeric"
oktocalc = false
else
if days = 0 then
msgbox "Days is 0--division by 0 not possible"
oktocalc = false
end if
end if

if oktocalc then
holOptElig = hours / days
else
'what should happen here?
end if

cellist wrote:


Dim days As Variant
Dim hours As Variant
Dim holOptElig As Variant
Dim wb As Workbook
Set wb = Workbooks("Salary and Hourly Summary 2009.xls")
days = wb.Names("MikeNbrHolidays").Value
hours = wb.Names("MikeTotalHolHours").Value
If days 0 Then
holOptElig = hours / days <== error on this statement
End If

In "Salary and Hourly Summary 2009.xls", MikeNbrHolidays and
MikeTotalHolHours are formatted as number/0 decimal places and
number/1 decimal places respectively, and their values are 8 and
43.2. I get run time error 13, type mismatch when I run this code.

TIA,

Phil


--

Dave Peterson

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Run time error 13, type mismatch

I see that now.

It usually a good idea to indicate the line that actually causes the error.
Else each responder may see problems in other portions and correct that.
(That's what happened to me!)

cellist wrote:

Dave, thanks for your reply. Turns out it was a different kind of problem in
this case, but your suggestion is right on as a defensive programming device.

"Dave Peterson" wrote:

I'd check both those variables.

dim OkToCalc as boolean

OkToCalc = true
if isnumeric(hours) = false then
msgbox "hours not numeric"
oktocalc = false
end if
if isnumeric(days) = false then
msgbox "days not numeric"
oktocalc = false
else
if days = 0 then
msgbox "Days is 0--division by 0 not possible"
oktocalc = false
end if
end if

if oktocalc then
holOptElig = hours / days
else
'what should happen here?
end if

cellist wrote:


Dim days As Variant
Dim hours As Variant
Dim holOptElig As Variant
Dim wb As Workbook
Set wb = Workbooks("Salary and Hourly Summary 2009.xls")
days = wb.Names("MikeNbrHolidays").Value
hours = wb.Names("MikeTotalHolHours").Value
If days 0 Then
holOptElig = hours / days <== error on this statement
End If

In "Salary and Hourly Summary 2009.xls", MikeNbrHolidays and
MikeTotalHolHours are formatted as number/0 decimal places and
number/1 decimal places respectively, and their values are 8 and
43.2. I get run time error 13, type mismatch when I run this code.

TIA,

Phil


--

Dave Peterson


--

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
Run-Time error, type Mismatch T De Villiers[_79_] Excel Programming 1 July 31st 06 03:28 PM
Run-time error 13, Type Mismatch T De Villiers[_73_] Excel Programming 2 July 31st 06 03:01 PM
Run Time Error 13 Type Mismatch ExcelMonkey Excel Programming 3 October 12th 05 12:51 PM
Run-time error '13':Type mismatch Sibilia[_9_] Excel Programming 2 July 3rd 05 08:54 PM
run time error 13 type mismatch kkknie[_170_] Excel Programming 0 July 20th 04 03:28 PM


All times are GMT +1. The time now is 10:39 PM.

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"