vba help - argument not optional

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I am converting working code into function. and calling from module.

Getting error argument not Optional. can you suggest whats wrong here. thanks.


Error line ------> If CheckMonth(str) = True Then


VBA Code:
Sub testMonths()

    Dim dict As New Scripting.Dictionary
    Dim s As String

    s = "ABC     USD     145,356        25jun2020         25Jun2020        18JUN2020           0.6 "
    

    If CheckMonth(str) = True Then
          dict.Add str, str
            
    End If

End Sub


Function CheckMonth(ByVal str As String) As Boolean

Months = Array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC")

    ns = UCase(s)

    MCnt = 0
    Do
        FoundMonth = False
        For Each MStr In Months
            If InStr(ns, MStr) > 0 Then
                FoundMonth = True
                MCnt = MCnt + 1
                ns = VBA.Replace(ns, MStr, "XXX", 1, 1)
                If MCnt >= 3 Then
                    'dict.Add s, s
                    CheckMonth = True
                    Exit Sub
                End If
            End If
        Next MStr
    Loop Until Not FoundMonth
End Sub


Thanks
mg
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
It should be
VBA Code:
    If CheckMonth(s) = True Then
          dict.Add s, s
            
    End If
 
Upvote 0
Hi fluff,

Thanks once again for help. you saved my time. (y) ?


Thanks
mg
 
Upvote 0
Just so you know why you got the missing argument error... Str is a built-in function in VBA and it requires an argument (VB saw you attempting to use it without providing its required argument, so it balked).
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,262
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top