Need help with VBA error-runtime error 13 type mismatch

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
179
Office Version
  1. 2019
  2. 2010
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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Micron

Well-known Member
Joined
Jun 3, 2015
Messages
4,199
Office Version
  1. 365
Platform
  1. Windows
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.
 

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
179
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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.
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,475
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
You may need to post your entire macro and a sample of data.
Are you declaring the cells as STRING
 

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
179
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
You may need to post your entire macro and a sample of data.
Are you declaring the cells as STRING
That's correct Michael. All declared as String.
 

Micron

Well-known Member
Joined
Jun 3, 2015
Messages
4,199
Office Version
  1. 365
Platform
  1. Windows
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.
 

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
179
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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.
 

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
179
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Problem was resolved when I was going through the script to copy and paste to this site. Thank you for your help.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
79,749
Office Version
  1. 365
Platform
  1. Windows
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.
 

Forum statistics

Threads
1,181,633
Messages
5,931,114
Members
436,776
Latest member
kranda

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
Top