Need help with VBA error-runtime error 13 type mismatch

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
246
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have an emailing script that is getting this runtime error 13 type mismatch.
It creates an email and find the contact and the email address(es) based on the below.
Not sure why it is suddenly throwing me these errors in the contact column. I tried to select the cells and change the option to IGNORE errors, but that didn't work. Chose the General, Text, and that didn't work either.
Help please!

VBA Code:
TempFilePath = "C:\temp\"

contact = Worksheets("Sheet1").Cells(1, "e").Value (contains letters and numbers - getting error)

toemail = Worksheets("Sheet1").Cells(1, "d").Value (email addresses and some contains mixed letters and numbers-getting error)

ccemail = Worksheets("Sheet1").Cells(2, "d").Value

subject = Worksheets("Sheet1").Cells(2, "a").Value

body = Worksheets("Sheet1").Cells(3, "a").Value

File = Worksheets("Sheet1").Cells(1, "a").Value
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
One or more of the cells probably contains no value? The message means you are trying to pass a value that is of some data type to variable/property that cannot accept it. Did you step through the code (F8) and check what the values are that you're trying to use/pass?

EDIT - you could try
Cstr(Worksheets("Sheet1").Cells(1, "e").Value) but that will likely error if the cell is blank.
 
Upvote 0
One or more of the cells probably contains no value? The message means you are trying to pass a value that is of some data type to variable/property that cannot accept it. Did you step through the code (F8) and check what the values are that you're trying to use/pass?

EDIT - you could try
Cstr(Worksheets("Sheet1").Cells(1, "e").Value) but that will likely error if the cell is blank.
Thank you Micron. None of the cells are empty
So, I tried your suggestion and now it throws error 2023 in the fields TO, CC, SUBJECT, and BODY.
 
Upvote 0
You may need to post your entire macro and a sample of data.
Are you declaring the cells as STRING
 
Upvote 0
Try Worksheets("Sheet1").Cells(1, "e").Text
If there is an error in a cell due to an expression/formula that returns #Value, #N/A, etc. then the problem might be there. I agree, post the rest of the code and some sample data. Suggestion: if you want assistance, don't make responders look up what your error number means if you can't provide the message. There are thousands of error numbers and I've made thousands of responses over the years. It just gets to be too much. It's compounded by the fact that some numbers have more than one message.
 
Upvote 0
Try Worksheets("Sheet1").Cells(1, "e").Text
If there is an error in a cell due to an expression/formula that returns #Value, #N/A, etc. then the problem might be there. I agree, post the rest of the code and some sample data. Suggestion: if you want assistance, don't make responders look up what your error number means if you can't provide the message. There are thousands of error numbers and I've made thousands of responses over the years. It just gets to be too much. It's compounded by the fact that some numbers have more than one message.
Thanks Micron. I already tried that and it threw #REF! errors in the TO & CC fields.
 
Upvote 0
Problem was resolved when I was going through the script to copy and paste to this site. Thank you for your help.
 
Upvote 0
Good to hear you got the solution.

If you would like to post the solution then it is perfectly fine to mark your post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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