Compile Error Type Mismatch Excel
Contents |
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards
Compile Error Type Mismatch In Vba
Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference compile error type mismatch access vba Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll
Vba Compile Error Type Mismatch Array Or User-defined Type Expected
be auto redirected in 1 second. Visual Basic Reference Visual Basic Language Reference Error Messages Error Messages Type mismatch (Visual Basic) Type mismatch (Visual Basic) Type compile error byref argument type mismatch mismatch (Visual Basic) '#ElseIf' must be preceded by a matching '#If' or '#ElseIf' '#Region' and '#End Region' statements are not valid within method bodies/multiline lambdas ' here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring type mismatch vb6 developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up VBA sub call gives “compile error: https://msdn.microsoft.com/en-us/library/3etdkytt.aspx Type mismatch: array or user-defined type expected” up vote 0 down vote favorite I have 2 Subs, both receive array as argument. one works fine, the other gives: compile error: Type mismatch: array or user-defined type expected. In the code written bellow, "InitializeArray" works and "PresentTotalRow" does not work. Can anyone figure out why? Sub PresentTotalRow(nCells As Integer, totalProductsPerDay() As Integer) row = nCells + MatrixRowOffset http://stackoverflow.com/questions/19513697/vba-sub-call-gives-compile-error-type-mismatch-array-or-user-defined-type-exp + 2 Range(Cells(row, 2), Cells(row, 8)) = totalProductsPerDay End Sub Sub InitializeArray(ByRef arr() As Long) Dim N As Long For N = LBound(arr) To UBound(arr) arr(N) = 0 Next N End Sub Sub ReadTxtFile() ..... Dim totalProductsPerDay(0 To 6) As Long InitializeArray totalProductsPerDay Dim filePath As String filePath = "C:\work\Documents\input.txt" Dim oFS As TextStream If oFSO.FileExists(filePath) Then Set oFS = oFSO.OpenTextFile(filePath) ...... i = 1 Do While Not oFS.AtEndOfStream line = oFS.ReadLine .... nCells = calcNCells totalProductsCounter = GetTotalProductsCounter() totalProductsPerDay(Day) = totalProductsPerDay(Day) + totalProductsCounter i = i + 1 Loop PresentTotalRow nCells, totalProductsPerDay oFS.Close Else MsgBox "The file path is invalid.", vbCritical, vbNullString Exit Sub End If Exit Sub End Sub Thanks, Li arrays excel-vba argument-passing share|improve this question asked Oct 22 '13 at 9:15 user429400 1,17432650 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted Sub PresentTotalRow(nCells As Integer, totalProductsPerDay() As Integer) row = nCells + MatrixRowOffset + 2 Range(Cells(row, 2), Cells(row, 8)) = totalProductsPerDay End Sub the second argument expects an integer array PresentTotalRow nCells, totalProductsPerDay you are passing an long array here as the second argument share|improve this answer answered Oct 22 '13 at 9:42 sam092 1,173157 here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company http://stackoverflow.com/questions/30924775/vba-type-mismatch-array-or-user-defined-type-expected-on-string-arrays Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up VBA "Type mismatch: array or user-defined type expected” on String Arrays up vote 1 down vote favorite I have a dynamic array of type mismatch strings DMAs which I declare globally. Dim DMAs() As String I ReDim the array and assign values to it in the CreateArrayOf function which is of type String() that returns an array of type String() DMAs = CreateArrayOf(Sites, 2, "", False) Public Function CreateArrayOf( _ ByRef arrayFrom() As String, _ Optional ByVal numOfChars As Integer = 2, _ Optional ByVal filterChar As String = "", _ Optional ByVal filterCharIsInteger As Boolean = False _ compile error type ) As String() Dim i As Integer, _ j As Integer, _ strn As Variant, _ switch As Boolean, _ strArray() As String 'numOfChars 2 for DMA with no filterChar 'numOfChars 3 for W with filterChar "W" 'numOfChars 3 for A with filterChar "A" 'numofChars 2 for D with filterChar "D" ReDim strArray(LBound(arrayFrom) To LBound(arrayFrom)) 'required in order to 'not throw error on first iteration For i = LBound(arrayFrom) To UBound(arrayFrom) 'iterate through each site switch = False For Each strn In strArray 'iterate through the array to find whether the 'current site already exists If strn = Mid(arrayFrom(i), 1, numOfChars) And Not strn = "" Then switch = True End If Next strn If switch = False Then 'if it doesn't exist add it to the array ReDim Preserve strArray(1 To UBound(strArray) + 1) strArray(UBound(strArray) - 1) = Mid(arrayFrom(i), 1, numOfChars) End If Next i CreateArrayOf = strArray 'return the new array End Function When I attempt to pass the DMAs array to another function OutputAnArray Private Sub OutputAnArray(ByRef arrayToOutput() As String) Dim i As Variant Dim x As Integer x = 1 For Each i In arrayToOutput Cells(x, 6).Value = i x = x + 1 Next i End Sub I get the "Type mismatch: array or user-defined type expected". Throughout the whole process I only mess with string arrayType Mismatch Excel Vba
Type Mismatch Vba Access