+ Reply to Thread
Results 1 to 7 of 7

"ByRef:mismatch" and "Constant Expression Required" Errors

  1. #1
    Registered User
    Join Date
    04-08-2015
    Location
    LA, CA
    MS-Off Ver
    2010 and 2013
    Posts
    18

    "ByRef:mismatch" and "Constant Expression Required" Errors

    Hello, I am new to writing Excel VBA functions and ran into issues writing up a function (that is specific to my worksheet).

    I am trying to get the sum all the values that can be found on one sheet (called "Reimbursements") within the workbook but are only relevant to the dates in the current worksheet (that can be found in the name of the current worksheet). However, all the values on "Reimbursements" are spread out across the worksheet with multiple columns (Valuesinit), and some of them are not relevant to me because their dates do not match (DReiminit) or they have been set to a status of FALSE (Reiminit).

    I first run into into a "ByRef:mismatch" on the red line of code, and then other times run into a "Constant expression required" on a purple line of code.

    The overall code is (additional Functions can be found after this overall code):

    Please Login or Register  to view this content.
    Some other code I used in the overall code that I have found throughout the web (and hereby should not be credited to me):

    Mysplitfunction:
    Please Login or Register  to view this content.
    piece:
    Please Login or Register  to view this content.
    FindAll:
    Please Login or Register  to view this content.
    I am currently switch between Microsoft Excel 2010 and 2013. If there is anything that requires clarification please tell me as this is my first time posting.
    Last edited by Mishil; 04-10-2015 at 04:00 PM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: "ByRef:mismatch" and "Constant Expression Required" Errors

    You declared SheetDateRng as a string, but your function returns an array of strings. Your other error is due to the fact that you can't declare a constant that depends on a property of a range (since it could vary). You need a variable.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    04-08-2015
    Location
    LA, CA
    MS-Off Ver
    2010 and 2013
    Posts
    18

    Re: "ByRef:mismatch" and "Constant Expression Required" Errors

    Thank you for responding!

    Some follow-up questions:
    1. For the first error, I thought the function takes in a single string, and outputs a single string? When I use the MySplitFunction in the worksheet itself, it produces a single string, hence my confusion (ex: Input is: "4-1-15--5-1-15 XXX", it outputs "4-1-15--5-1-15" normally).
    2. For the second error, do you then recommend replacing the line with something like....
      Dim rngSize As Integer
      rngSize = Valuesinit.Column.Count
      ?

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: "ByRef:mismatch" and "Constant Expression Required" Errors

    No - your function is declared to return an array of strings, hence the As String() rather than As String at the end of the declaration.

    Yes, but it's Columns.Count

  5. #5
    Registered User
    Join Date
    04-08-2015
    Location
    LA, CA
    MS-Off Ver
    2010 and 2013
    Posts
    18

    Re: "ByRef:mismatch" and "Constant Expression Required" Errors

    Ah! Thank you! I'll try it out now.

  6. #6
    Registered User
    Join Date
    04-08-2015
    Location
    LA, CA
    MS-Off Ver
    2010 and 2013
    Posts
    18

    Re: "ByRef:mismatch" and "Constant Expression Required" Errors

    The first issue has been solved (THANK YOU!)

    But even with your suggested changes, the debugger still complains (about the second issue) that a "Constant Expression is Required." Even though rngSize should not be an array, should I use ReDim?

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: "ByRef:mismatch" and "Constant Expression Required" Errors

    You need:
    Please Login or Register  to view this content.
    rather than:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to assign a ImputBox to a "Constant expression"
    By capson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-26-2014, 12:19 PM
  2. [SOLVED] "ByRef argument type mismatch error" trying to use my first UDF
    By capson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-23-2014, 08:46 PM
  3. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  4. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  5. "ByRef argument type mismatch" Error
    By Baapi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2005, 08:05 PM

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