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: 13
Default Optional argument as Variant not acting like number

I'm using an Optional Argument as Variant in a code, but the code doesn't seem to be treating the argument as a number. Do I need to re-declare it as integer? or coerce it into number? here's the code that is resulting in error:

In a sheet with week number "1x3" for example, column A contains product names, column B contains codes. The codes contain the shift number in the 4th position (1, 2, or 3).

I want to count how many times the codes contain the shift number requested by the user. From what I can figure, it seems the code isn't treating the digit pulled out of the code as a number. Little help?


Function TotalCC(Week As String, Optional ShiftNum As Variant) As Integer

'Application.Volatile

'item ranges based on sheet name
Set ProductRange = Sheets(WeekNum).Range("A1:A100")

'initialize
CountVals = 0

'check for shiftnum argument
If IsMissing(ShiftNum) Then
'do some stuff - in this case, the shift argument is present
ElseIf Not IsMissing(ShiftNum) Then
For Each ProductCell In ProductRange
If Mid(ProductCell.Offset(0, 1).Value, 4, 1) * 1 = ShiftNum * 1 Then
On Error Resume Next
CountVals = CountVals + 1
ElseIf Len(ProductCell.Offset(0, 9).Value) < 4 Then
CountVals = CountVals + (1 / 3)
End If
Next
End If

TotalCC = CountVals

End Function

Here's how I enter the function in the worksheet: =TotalCC("1x2",3)

 
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
Argument not optional Arne Hegefors Excel Programming 4 August 30th 06 04:08 AM
Optional Variant Desert Piranha[_110_] Excel Programming 5 August 23rd 06 02:37 PM
Argument not optional Error 449! Need Help bad_boyu Excel Programming 3 July 26th 06 12:52 PM
Don't understand why I'm getting an argument not optional Brett Smith[_2_] Excel Programming 2 February 8th 06 02:05 PM
optional argument in a function visitor Excel Programming 4 May 13th 05 07:41 PM


All times are GMT +1. The time now is 04:58 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"