Type Mismatch, dynamic string array.

jamesblack90

New Member
Joined
Jun 9, 2015
Messages
44
Hey all, I'm sure this is something really simple so apologies - first time using anything other than recorded macros to change which worksheet you're on >.<

I am getting a type mismatch error on the
Code:
errmessage(errcount) = xxxx
lines

I have tried declaring errmessage() as variant and as string and neither seem to work. Any thoughts?

Code:
Private Sub check_errors()


Dim errFlag As Boolean
Dim errCount As Integer
Dim errMessage() As Variant
Dim i As Integer, j As Integer


errCount = 0


    If Not Range("name_c1").Value = "" And (Range("status_c1").Value = "" Or Range("deps_c1").Value = "") Then
        errFlag = True
        errMessage(errCount) = "Please fill out all fields for " + Split(Range("name_c1").Value) + "."
        errCount = errCount + 1
    End If
    
    If Not Range("name_c2").Value = "" And (Range("status_c2").Value = "" Or Range("deps_c2").Value = "") Then
        errFlag = True
        errMessage(errCount) = "Please fill out all fields for " + Split(Range("name_c2").Value) + "."
        errCount = errCount + 1
    End If
    
    If Not Range("name_c3").Value = "" And (Range("status_c3").Value = "" Or Range("deps_c3").Value = "") Then
        errFlag = True
        errMessage(errCount) = "Please fill out all fields for " + Split(Range("name_c3").Value) + "."
        errCount = errCount + 1
    End If
    
    If Not Range("name_c4").Value = "" And (Range("status_c4").Value = "" Or Range("deps_c4").Value = "") Then
        errFlag = True
        errMessage(errCount) = "Please fill out all fields for " + Split(Range("name_c4").Value) + "."
        errCount = errCount + 1
    End If


    If errFlag = True Then 
        Range("C29").Value = "Errors:"
    
        For i = LBound(errMessage) To UBound(errMessage)
            j = i + 29
            Cells(j, 3).Value = "'- " + errMessage(i)
        Next i
   End If
 
End Sub

Thanks in advance :)
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
That array has to be dimensioned before you use it. So, prior to use you need something like this:

Redim errMessage(1 to errcount+1)
 
Upvote 0
Oh ofcourse it does! Thanks Joe! I tried adding
ReDim Preserve errMessage(0 To errCount + 1)
Above the affected lines but I'm still getting the type mismatch error.
 
Upvote 0
Oh ofcourse it does! Thanks Joe! I tried adding
ReDim Preserve errMessage(0 To errCount + 1)
Above the affected lines but I'm still getting the type mismatch error.
In the assignment of errmessage elements change the + signs to & (see below in red font)
Rich (BB code):
errMessage(errCount) = "Please fill out all fields for " + Split(Range("name_c1").Value) + "."
 
Upvote 0

Forum statistics

Threads
1,206,816
Messages
6,075,036
Members
446,114
Latest member
FadDak

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