+ Reply to Thread
Results 1 to 9 of 9

ByRef Argument Type Mismatch - problem with Range.

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    20

    ByRef Argument Type Mismatch - problem with Range.

    I have three functions .
    The main function which gets called from Workbook is "getRefi"| (as given below).
    it s second line - SecuredLastRange = getLastValueInList(SecuredFirstRange) - throws the error, Can you please tell me what is worng in my VBA code ?

    Public Function getRefi(rownum As Integer) As String
    SecuredFirstRange = Sheets("Data").Range("K5")
    SecuredLastRange = getLastValueInList(SecuredFirstRange) -- This line throws , ByRef Argument Type mismatch
    End Function

    Public Function getLastValueInList(TimeBucketData As Range) As Range
    Do While hasNextRow(TimeBucketData)
    TimeBucketData = TimeBucketData.Offset(1, 0)
    Loop
    getLastValueInList = TimeBucketData
    End Function

    Public Function hasNextRow(rownum As Range) As Boolean
    If rownum.Offset(1, 0) <> "" Then
    hasNextRow = False
    Else
    hasNextRow = True
    End If
    End Function

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: ByRef Argument Type Mismatch - problem with Range.

    please add code tags to your post

    you have not declared the variable as a range or assigned a range to it
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    03-27-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: ByRef Argument Type Mismatch - problem with Range.

    Thanks a lot , it s been resolved.
    If you can resolve one confusion over this issue.
    Do we need to declare all the variables using "Dim" in EXCEL VBA and set their valye using "Set"? As many times i do not declare them but still it works and with "Set" i used to set the values.
    Last edited by syparth; 04-15-2013 at 08:26 AM. Reason: i forgot to add something

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: ByRef Argument Type Mismatch - problem with Range.

    generally you don't need to but it is recommended by most

    if you wish to pass data byref to your routines and that type is not Variant then you will need to declare it (if the data needs to be changed by the called routine)

  5. #5
    Registered User
    Join Date
    03-27-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: ByRef Argument Type Mismatch - problem with Range.

    Thanks a lot. Thankyou.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: ByRef Argument Type Mismatch - problem with Range.

    I didn't see your edit

    you have to use Set when you are dealing with object variables (like ranges, worksheets, workbooks) but not with data types (integers, strings, dates)

  7. #7
    Registered User
    Join Date
    03-27-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: ByRef Argument Type Mismatch - problem with Range.

    Ok, Thanks,
    I edited to add "Set" question.
    Thank you very much.

  8. #8
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: ByRef Argument Type Mismatch - problem with Range.

    Do we need to declare all the variables using "Dim" in EXCEL VBA and set their valye using "Set"?
    For Object types (eg Range, Worksheet) you need to use the Set keyword. There's a Let keyword for literal types (eg String, Integer) but it's optional and is usually omitted in VBA code.

    If you have an Option Explicit statement at the top of your code module then you must declare your variables. This is a good practice because declaring your variables will help you avoid hard to spot errors in your code such as typos and it will improve your understanding of what the code is really doing. Using Option Explicit can be a bit frustrating when you first start writing VBA because the VBA IDE might complain and give you some compile errors: I encourage you to persevere with it and we are always here to help you if you're not sure what the problem is. You'll be a better coder for it.
    Hope that helps,

    Colin

    RAD Excel Blog

  9. #9
    Registered User
    Join Date
    03-27-2013
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: ByRef Argument Type Mismatch - problem with Range.

    Thank you so much for kind support.
    I thank this forum.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1