How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Jason Jones Your Own Question
Jason Jones
Jason Jones, Computer Expert
Category: Computer
Satisfied Customers: 16028
Experience:  Over 10 years of professional experience.
Type Your Computer Question Here...
Jason Jones is online now
A new question is answered every 9 seconds

I have the following lines of code. Sometimes, there will be

Customer Question

I have the following lines of code. Sometimes, there will be an error from the line of code:Else: concat = concat & " ~ " & Cells(i, j).Value. The error depends on the type of the cell variable. The error message is 'Type mismatch'. How can I change the code to make it more robust. The VBS program is to write excel files into text files.
For i = 1 To numrows
concat = " "
For j = 1 To numcols
If j = 1 Then
concat = Cells(i, j).Value
Else: concat = concat & " ~ " & Cells(i, j).Value
End If
Next j
If concat String(Len(concat), "|") Then ' i.e. all data in row is blank
concat = Replace(concat, Chr(10), " ") ' removes return characters
Print #fn, concat
End If
Next i
Submitted: 2 years ago.
Category: Computer
Expert:  Jason Jones replied 2 years ago.

If anyone wishes to ask Jason a question directly,
they can do so at the following page:

My name is Jason. I look forward to helping you today.
Without seeing the values that they are pulling, I must assume that the problem is due to the fact that it is not trying to add the value as text.
Change the following line to match the one below it:
Else: concat = concat & " ~ " & Cells(i, j).Value
Correct code:
Else: concat = concat & " ~ " & Cells(i, j).Text
That will fix your problem.
I look forward to your next message or your rating below.
Please, do not forget to rate my help on this page.
Thank you again,
- Jason

Related Computer Questions