1

I'm having an issue that I can't quite figure out through google searching. I'm constructing a string based on cell content within a workbook and values from a variant array and getting a type mismatch error when the code reaches the argument where I construct the string. Code below. Any help is appreciated, thanks!

    Dim taskAssignments As String
        taskAssignments = ws.[getTaskAssignment] & var(i, 1) & ws.[getTaskAssignment2]
4
  • 1
    There's not nearly enough information here to give you a definitive answer. Exactly what is getTaskAssignment/getTaskAssignment2 (seriously? how about meaningful names?) and what's its value? Commented Mar 28, 2017 at 15:57
  • Try putting each of the 3 into the taskAssignments string one at a time to see which one is causing the issue? Commented Mar 28, 2017 at 15:57
  • 1
    Try it as ws.Range("getTaskAssignment") in both places. Commented Mar 28, 2017 at 15:58
  • 1
    if getTaskAssignment and getTaskAssignment2 are the names of two named ranges local to the same worksheet to which ws is a valid object reference, then your code is likely to fail in the var(i, 1) part -> wrap it in a Cstr() call Commented Mar 28, 2017 at 16:05

1 Answer 1

3

Try wrapping each value in CStr() to explicitly convert the values to a String:

taskAssignments = CStr(ws.[getTaskAssignment]) & cstr(var(i, 1)) & cstr(ws.[getTaskAssignment2])
Sign up to request clarification or add additional context in comments.

3 Comments

If the cell contains an error, this will blow up all the same.
Also try using .Value at the end of every range. such as ws.[getTaskAssignment].Value ... you can combine this with Cstr() if needed.
this worked - thanks. the cell didn't contain an error, I've already vetted that. I'll accept the answer in a few.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.